使用WordPress中的函数has_posts

时间:2016-10-12 07:33:08

标签: php wordpress

我正在使用WordPress codex中的函数have_posts。我想做的是:

while ($content_query->have_posts()) {

         $content_query->the_post();
         if(strpos(the_title(),'Garajes Gran')===false){        
            global $post;
            include($item_template);

         }

        }

所以我得到了包含Garajes Gran名字的完整名单,而不是没有名字Garajes Gran的名单,我做错了什么?而不是寻找字符串Garajes Gran的第一个位置,它打印所有名称,所以为什么 if(strpos(the_title(),' Garajes Gran')=== false){没有做到这意味着什么?。

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码'get_the_title()'而不是'the_title()'。

if(strpos(get_the_title( get_the_ID() ),'Garajes Gran')===false){        
    global $post;
    include($item_template);
}

我希望这对你有用。