尝试使用此选项:
// Get the \'WpForest_soft\' custom field value.
$text = get_post_meta( $post->ID, \'WpForest_soft\', true );
// Print the value and surrounding markup only if the value tests true.
if ( $text )
printf( \'<tr><td class="attr-name">%s</td><td class="attr-detail">%s</td></tr>\', __( \'Software Version\', \'WpForest\' ), $text );
一般情况
要使用任何可选标记执行上述操作,请执行以下步骤。
1) 将的自定义字段值放置在变量中。使用相关变量名。
// Get the \'WpForest_soft\' custom field value.
$wpforest_soft = get_post_meta( $post->ID, \'WpForest_soft\', true );
2)编写一个PHP条件测试步骤1中的值。
if ( $wpforest_soft ) {
}
3)将标记添加到该条件中。
if ( $wpforest_soft ) {
?>
<a href="<?php bloginfo(\'url\'); ?>/theme-demo/<?php echo the_ID(); ?>" class=\'blue-btn right ml10 live-preview\' target=\'_blank\'>Live Preview</a>
<a href="<?php bloginfo(\'url\'); ?>/theme-demo/<?php echo the_ID(); ?>" class=\'blue-btn right ml10 live-preview\' target=\'_blank\'>Video Preview</a>
<a href="<?php bloginfo(\'url\'); ?>/screenshots/<?php echo the_ID(); ?>" class=\'blue-btn right ml10 screenshots\' target=\'_blank\'>Screenshots</a>
<?php
}
4)(可选)避免跳入和跳出PHP和标记。这个
printf() PHP函数可以提供帮助。
if ( $wpforest_soft ) {
printf(
\'<a href="%1$s/theme-demo/%2$s" class="%3$s" target="_blank">Live Preview</a>\' .
\'<a href="%1$s/theme-demo/%2$s" class="%3$s" target="_blank">Video Preview</a>\' .
\'<a href="%1$s/screenshots/%2$s" class="%4$s" target="_blank">Screenshots</a>\',
get_bloginfo( \'url\' ),
get_the_ID(),
\'blue-btn right ml10 live-preview\',
\'blue-btn right ml10 screenshots\'
);
}
或者只是:
if ( $wpforest_soft )
printf(
\'<a href="%1$s/theme-demo/%2$s" class="%3$s" target="_blank">Live Preview</a>\' .
\'<a href="%1$s/theme-demo/%2$s" class="%3$s" target="_blank">Video Preview</a>\' .
\'<a href="%1$s/screenshots/%2$s" class="%4$s" target="_blank">Screenshots</a>\',
get_bloginfo( \'url\' ),
get_the_ID(),
\'blue-btn right ml10 live-preview\',
\'blue-btn right ml10 screenshots\'
);