【问题标题】:How to check to see if wordpress shortcode has $content如何检查 wordpress 短代码是否有 $content
【发布时间】:2014-07-17 02:13:54
【问题描述】:

我有一个自封闭的短代码,我将使用帖子 ID 从中提取内容,但是当我不使用短代码的自封闭部分而只使用短代码时,我希望它使用当前的帖子 ID 所以如何检查自封闭内是否有任何内容?

当我想从另一个帖子中提取内容时,我将使用短代码,例如 [deck]172[/deck],其中 172 将是我要从中提取内容的帖子 ID,但如果我想从当前帖子中提取内容我只想使用 [deck] 所以我不确定如何检查自封闭中是否有任何内容

add_shortcode( 'deck', 'deck_shortcode' );
function deck_shortcode( $atts ,$content = null) {

    if (Check to see if $content exist)  {
       $deck_id = $content;
    } else {
        $deck_id = $post->ID;
    }

}

这是我正在寻找的逻辑类型我只是不确定如何检查短代码是否是自封闭的并且在 $content 中有任何内容

【问题讨论】:

    标签: php wordpress shortcode


    【解决方案1】:

    empty() 是你要找的。​​p>

    if (!empty($content))  { // if not empty, then
           $deck_id = $content; // do this
        } else {
            $deck_id = $post->ID;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 2014-03-23
      相关资源
      最近更新 更多