不确定这是否是处理这个问题的最佳方法,但我需要从循环中删除贴子,我仍然需要在第一页上显示贴子,但由于我使用了一个无休止的列表,我不想要它出现了两次。这行得通,但是编辑 index.php 文件来完成它感觉有点骇人听闻……还有其他想法吗?
//Get the current page number
$url_args=explode('/',trim($_SERVER['REQUEST_URI'],'/'));
$page_number=array_pop($url_args);
$sticky=get_option('sticky_posts');
//if no page number, we are on the home page, so stickies are ok
$print_it=($page_number=='')?true:(in_array(get_the_ID()*1,$sticky)?false:true);
更容易阅读的 if 语句:
if($page_number=='' || !in_array(get_the_ID(),$sticky)) $print_it=true;
else $print_it=false;