简体   繁体   中英

WordPress Sticky Posts

I have a site where on the home page there are teasers for the 3 most recent posts.

If I make a post sticky then it actually adds a fourth post display and so on.

After searching I found this script which seem to initially work:

<?php
    $sticky = count(get_option('sticky_posts')); 
    $the_query = new WP_Query( 'posts_per_page='. ( 3 - $sticky));
?>

This seemed to do the job perfectly. However I found if one of the posts was a recent post and was also set to sticky then this would affect the amount displyed.

For example, it the second most recent post was made sticky then it would result in only two posts displaying.

Any ideas on how the above code can be altered to always show three posts, sticky or not?

Thanks

$args = array(
    'posts_per_page' => 3,
    'ignore_sticky_posts' => 1
);
query_posts($args);

-- use while loop here ---

and after that use

wp_reset_query();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM