从最近的帖子查询中排除我正在查看的当前帖子的最佳方法是什么。非常感谢。
<?php
global $post;
if (in_category(\'top-lists\')) {
$myposts2 = get_posts(\'numberposts=5&offset=0&category=7\');
}
else if (in_category(\'playlists\') || in_category(\'playlistall\')) {
$myposts2 = get_posts(\'numberposts=5&offset=0&category=6,37\');
}
else if (in_category(\'news\') || in_category(\'news\')) {
$myposts2 = get_posts(\'numberposts=5&offset=0&category=95\');
}
else {
$myposts2 = get_posts(\'numberposts=5&offset=0&category=-6,-7,-37,-95,-177\');
}
foreach($myposts2 as $post) :
?>
最合适的回答,由SO网友:Brian Fegter 整理而成
这是post__not_in
arg应该对您非常有用:
$args = array(
\'numberposts\' => 5,
\'offset\' => 0,
\'category\' => 7,
\'post__not_in\' => array( $post->ID )
);
$myposts2 = get_posts($args);