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
评论列表(0条)