在下面的函数中,我试图从输出循环中删除当前帖子(因为这是一个“相关”帖子的列表)。
然而,当我试图将当前的post$post->ID传递给“post\\u not\\u in”参数时,一切都很混乱。
警告:array\\u map()[函数.数组映射]:参数#2应该是C:\\xamplite\\htdocs\\thetereport\\wp includes\\query中的数组。php在线1826
警告:implode()[函数.implode]:在C:\\xamplite\\htdocs\\theteareport\\wp includes\\query中传递的参数无效。php在线1826
警告:array\\u diff()[函数.array diff]:参数#2不是C:\\xamplite\\htdocs\\thetereport\\wp includes\\query中的数组。php在线2496
正确的方法是什么?
//get related posts by category
function ce4_get_related_by_category()
{
global $post;
$cat = implode(\',\',get_cats());
$catHidden=get_cat_ID(\'hidden\');
$myqueryCurrent = new WP_Query();
//$myqueryCurrent->query(array(\'cat\' => "$cat,-$catHidden",\'post__not_in\' => get_option(\'sticky_posts\')));
$myqueryCurrent->query(array(\'cat\' => "$cat,-$catHidden",\'post__not_in\' => $post->ID));
$totalpostcount = $myqueryCurrent->found_posts;
if($totalpostcount > 0)
{
echo "<ul>";
$myposts = get_posts(array(\'cat\' => "$cat,-$catHidden",\'numberposts\' => $cb2_current_count));
foreach($myposts as $idx=>$post)
{
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php the_excerpt(); ?></li>
<?php
}
echo "</ul>";
}
}