WordPress.org

Forums

Problem with Sticky and Recent Pots (9 posts)

  1. Wiki Chaves
    Member
    Posted 5 years ago #

    Hi,

    I´m having a problem with sticky and recent posts

    I wan to have in the front page of my blog (http://bloggertone.com/) allways 4 posts. And I want to be able to (if i want) use sticky posts in order to my convenience.

    What i´ve first done is to query last 4 posts, but if i´ve selected 2 stickies the frontpage showed me 6 posts (2 stickies first, then 4 recent)

    So what i did is this query
    <?php query_posts('caller_get_posts=0&cat=-19&showposts='. ( 4 - $sticky ));?>

    Everything seemed to be OK but then i´ve realized that if i marked one recent posts as sticky, the frontpage only showed me 3 posts (4 posts - 1 sticky)

    Does it makes any sense ?
    Is there a way to fix this ?

    Thanks !
    Wiki

  2. esmi
    Forum Moderator
    Posted 5 years ago #

  3. Wiki Chaves
    Member
    Posted 5 years ago #

    Hmm, I´ve just tried but didn´t worked.

    Any other idea ?

    Thanks!

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    query_posts(array("post__not_in" =>get_option("sticky_posts")));
    ??

  5. Wiki Chaves
    Member
    Posted 5 years ago #

    Nope :(

    first cause i want to show only 4 posts and exclude categroy 19.

    Then, i Dont`t want to exclude sticky. What I want is to be counted as 1 post, not as a duplicated post (if is recent and sticky it counts me as twice)

    Thanks !

  6. Wiki Chaves
    Member
    Posted 5 years ago #

    As I´ve seen it´s a WP bug not solved yet
    http://core.trac.wordpress.org/ticket/9300

    Does anybody know some hack to solve this ?

    Thanks
    Wiki

  7. vtxyzzy
    Member
    Posted 5 years ago #

    Brute force? Use two loops, first for stickies up to 4 (count stickies), second for recent not sticky, retrieve 4 - sticky_count if sticky_count < 4.

  8. Wiki Chaves
    Member
    Posted 5 years ago #

    Hmm I have tried some kind of these, but stickies counts different if it is siticky and recent and if it is only sticky.

    Anyway i would like to try again.

    Do you know the code i should use in the query ?

    regards,
    Wiki

  9. vtxyzzy
    Member
    Posted 5 years ago #

    I don't have a complete example, but look at this post for how to get the n recently posted (or recently made sticky) posts.

    Then count the number actually shown in the first loop.

    If less than 4 were shown, for the second loop, retrieve the 4 most recent posts. In the loop, show only if (!s_sticky(get_the_ID())) and the total count shown < 4.

Topic Closed

This topic has been closed to new replies.

About this Topic