loop - Custom Query with Sticky Posts

I’m trying to write a custom query which filters by category and shows only a certain number of posts. So far that’s a s

I’m trying to write a custom query which filters by category and shows only a certain number of posts. So far that’s a simple thing along these lines:

$args = array(
 'showposts' => 1,
 'cat' => ‘category',
);

The problem arises when sticky posts enter the picture. If I mark a post as sticky it is ADDED to the total instead of simply pushing everything else down and keeping the correct number of posts visible.

I’ve attempted to create custom loops which deal with this using complicated if/else rules, e.g.

$categoryvariable = $cat;
$args = array(
  'posts_per_page' => 1,
  'post__in' => get_option( 'sticky_posts' ),
  'ignore_sticky_posts' => 1,
  'cat' => $categoryvariable,
  'showposts' => 1
);

These don’t work well and I suspect they’re more complicated than they should be and thus will cause problems later. Most of them show ONLY sticky posts, too, so if a post in any category is marked as sticky then all other posts site-wide stop being served.

This seems so counter-intuitive compared to the rest of WordPress' systems. Am I missing something, or can someone help me figure out how to do this?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745009903a4606003.html

相关推荐

  • loop - Custom Query with Sticky Posts

    I’m trying to write a custom query which filters by category and shows only a certain number of posts. So far that’s a s

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信