php如果meta shortcode空不显示,如果得到文本echo文本

时间:2013-03-17 15:36:44

标签: php wordpress

如果我的元框短代码中没有显示任何内容,我不会显示任何内容:

<?php echo stripslashes(do_shortcode(get_post_meta($post->ID, '_'.$dirname.'_matchquote', true))); ?>

元框短代码的编码如下:

'_'.$dirname.'_matchquote' => array(
    'name' => '_'.$dirname.'_matchquote', 
    'title' => __('Match Quote', 'gp_lang'), 
    'desc' => __('', 'gp_lang'), 
    'std' => '',
    "type" => "textarea"
),

那么,如果某个盒子里面什么都没有,我该如何回应呢?

1 个答案:

答案 0 :(得分:0)

目前还不清楚“那个特定的盒子”是什么,但我认为这就是你想要的:

$text = stripslashes(do_shortcode(get_post_meta($post->ID, '_'.$dirname.'_matchquote', true)));
if (!empty($text)) {
  echo $text;
}

我不明白为什么你在处理过的短代码上运行stripslashes。如果有的话,我认为它应该在get_post_meta的输出之前运行,然后才能将该字符串发送到do_shortcode

$text = do_shortcode(stripslashes(get_post_meta($post->ID, '_'.$dirname.'_matchquote', true)));
if (!empty($text)) {
  echo $text;
}