我在自定义循环中显示粘性帖子时遇到问题。这是我用于自定义循环的代码:
<?php
$post_from_cat_a = new WP_Query(array(
\'category_name\' => \'events\', //Get posts from category a
\'posts_per_page\'=> 2 //Limit it to the latest one
));
if( $post_from_cat_a->have_posts() ){
while( $post_from_cat_a->have_posts() ): $post_from_cat_a->the_post(); //Display output here for post from category a
$category = get_the_category();
if($category[0]){
echo \'<div class="cat-events"><a href="\'.get_category_link($category[0]->term_id ).\'">\'.$category[0]->cat_name.\'</a></div>\';
}
get_template_part( \'content\', \'events\' );
endwhile;
}
?>
我不明白为什么它不起作用。Later edit: 这是我的全部homepage.php 出现问题的位置,这是content-events.php 用于事件类别中每个帖子的文件。
Second edit: 如果我包括\'post__in\' => get_option(\'sticky_posts\')
在wp_query
数组显示粘性帖子,但不会列出类别中的下一篇帖子。页面上只显示粘性帖子,这有点忽略了\'posts_per_page\'=> 2
论点
有人知道为什么会这样吗?