当我在single.php中过滤它们时,为什么我会得到每个帖子的每个标题

时间:2013-11-05 16:21:11

标签: php wordpress filtering title

我正在处理页面和帖子中的过滤器标题,一切都按预期工作但当我查看single.php而它显示实际的帖子应该是,函数钩子过滤器我正在函数内部的function.php我的插件正在过滤我博客每个帖子的每个标题,我希望只过滤当前帖子的标题:

add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) { 
    if((in_the_loop())){ 
      /**/
    }    
}

任何帮助都很感激。

谢谢;)

2 个答案:

答案 0 :(得分:0)

add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) { 
    if((some condition true)){ 
     $add_this = 'some string';
     $new_title = $title.' '.$add_this;
      return $new_title;
    }   

      return $title; 
}

当您查看任何帖子时,它会通过single.php显示,因此当您查看时,每个帖子都会成为当前帖子

答案 1 :(得分:0)

我现在明白,对于过滤器标题钩子来说,查看single.php中的单个帖子与查看整个博客相同。是否有一种过滤条件的方法只能在single.php中检索当前帖子的标题?我确实试过“get_the_title(get_the_ID())”这样但很明显我无法嵌套它。

add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) { 
    if((in_the_loop())){ 
      if(is_single()){
        $title=get_the_title(get_the_ID());
      }
    }    
}