从WordPress中的特定类别获取粘性帖子

我想检查某个类别是否有粘性帖子。为此, 我使用$ sticky = get_option(‘sticky_posts’);在archive.php上。

但是它显示了博客中的所有粘性帖子。不仅来自显示的类别。我可以添加任何内容以仅显示所显示类别或标签中的粘性帖子吗?

如果有粘性帖子, 我需要的是对/错。如果有粘性帖子, 我需要一个带有ID的数组。


#1


希望以下代码能对你有所帮助:

    $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();

有关更多帮助, 请参见此链接, 请单击此处。

来源:

https://www.srcmini02.com/65112.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37332.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?