我能够找到答案的一部分,我是Wordpress的新手。我希望在主页上显示随机帖子,但除了我发现的最后一个帖子,
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('orderby', 'rand');
}
}
先感谢您
这是代码,请在functions.php文件中使用此代码,然后输入您需要排除该帖子的最后一个帖子ID。
add_action('pre_get_posts','my_pre_get_posts');
function my_pre_get_posts($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('orderby', 'rand');
$query->set('post__not_in',array(1));
}
}
请使用它,并且我也在搜索一种最佳解决方案,在该解决方案中,您无需输入静态的最后一个帖子ID = 1。 本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句