[英]Get sticky posts from specific category in WordPress
我想检查某个类别是否有粘性帖子。 为此,我使用$sticky = get_option( 'sticky_posts' );
在archive.php
。
但是它显示了博客中的所有粘性帖子。 不仅来自显示的类别。 我可以添加任何内容以仅显示所显示类别或标签中的粘性帖子吗?
如果有粘性帖子,我需要的是对/错。 如果有粘性帖子,我需要一个带有ID的数组。
希望以下代码能对您有所帮助:
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$sticky = get_option( 'sticky_posts' );
$args = array(
'cat' => 3,
'ignore_sticky_posts' => 0,
'post__in' => $sticky,
'paged' => $paged
);
$sticky_posts = new WP_Query( $args );
if ( $sticky_posts->have_posts() ) : while ( $sticky_posts->have_posts() ) :
$sticky_posts->the_post() );
//Loop markup here
endwhile; endif;
//IMPORTANT
wp_reset_postdata();
有关更多帮助,请参见此链接, 请单击此处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.