$sticky = get_option( \'sticky_posts\' );
$args = array(
\'post_type\' => \'post\' ,
\'orderby\' => \'date\' ,
\'order\' => \'DESC\' ,
\'posts_per_page\' => 4,
\'cat\' => \'3\',
\'paged\' => get_query_var(\'paged\'),
\'post__in\' => isset( $sticky[0] ) ? $sticky[0] : array(),
\'ignore_sticky_posts\' => 1,
);
$q = new WP_Query($args);
上面的代码将只包括第一个粘性帖子,如果它不存在,它将获得正常帖子。
如果要显示所有现有的粘性帖子,请使用以下代码:
$args = array(
\'post_type\' => \'post\' ,
\'orderby\' => \'date\' ,
\'order\' => \'DESC\' ,
\'posts_per_page\' => 4,
\'cat\' => \'3\',
\'paged\' => get_query_var(\'paged\'),
\'ignore_sticky_posts\' => false,
);
$q = new WP_Query($args);