• Resolved banago

    (@banago)


    Hi everybody!

    I have a problem with my loops. WordPress default loop counts (not duplicate) my featured articles’ loop posts.

    I have a featured articles section showing 5 articles. The default loop is set to show 10 articles. But it just shows 5 in front page as it counts the 5 posts of the featured articles loop. When I click next it shows 10 posts, so the problem exist only in front page.

    Please find below the code:

    Default loop:

    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate[$post->ID] ) continue; ?>
    
    <?php the_title(); ?>
    
    <?php the_excerpt(); ?>
    
    <?php endwhile; endif; ?>

    Featured posts loop:

    <?php $my_query = new WP_Query('category_name=featured&showposts=5');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate[$post->ID] = $post->ID; ?>
    
    <?php the_title(); ?>
    
    <?php the_excerpt(); ?>
    
    <?php endwhile;?>

    How to make the main loop not count the posts of the featured loop?

    Thanks very much!

    Banago

Viewing 10 replies - 1 through 10 (of 10 total)
  • Try

    <?php $my_query = new WP_Query('category_name=featured&showposts=5&offset=1');

    Thread Starter banago

    (@banago)

    Thanks Evita. Actually it just removed 1 post, I need to add on 🙂 Thanks though!

    So, this may be too basic, but I really think it is probably the actual blog setting in the Reading tab.

    Try bumping up the “Blog pages show at most” to 15 and I think it should work. The system is really just doing as its told – the main page is limiting the posts to whatever you have in there – likely 10?

    Your featured posts are 5 and so the second loop pulls at most 5.

    So that the second pages don’t pull 15 posts, I’d engineer the main loop to add a showposts=10, if you really care.

    Anyway, I could be way off on this, but I think it may be that simple???

    Good luck,
    A

    Thread Starter banago

    (@banago)

    Thanks for the time Miloandrew. I have tried to set a showposts to the main loop but it ignores it. this does not help. I think there is a code to be added for the:

    $post->ID

    Any other idea?

    It was very late yesterday, sorry, forget my post.
    WordPress navigation don´t love query posts. If your setting in admin reading page is 10, then your second blog page will always show 10 posts starting with number 11, no matter what the code on the first page is. I believe, there is no hack for this.

    Thread Starter banago

    (@banago)

    That is bad news. But there is hope too. I can see this alive at http://www.wp-magazine.com. I have adopted some of its code too. There is a way out for sure. Any other suggestion would be very appreciated.

    @banago – did you try setting the overall post number to 15 in the Reading settings? Just curious if that worked at all for the first page – problems with the second page notwithstanding…

    Cheers,
    A

    wp-magazine.com has 15 posts on their home page and 9 on the second page, starting with post 11.
    I think, their reading settings are 10 posts, featured posts are in more than one category and they are using two query_posts on the homepage – one for the featured articles and one for the recent posts.
    I don´t know their code, but I think, there is no magic code behind.

    Thread Starter banago

    (@banago)

    @miloandrew – actually I have set it to 14 posts, 5 in the featured and 9 at the main loop. When you click older posts it displays 14.

    @evita – I have used the code of the wp-magazine at my project. The guys there make use a some extra lines I think but I do not know what they are. Unfortunately my PHP knowledge is still little.

    Thanks a lot for your time.

    Thread Starter banago

    (@banago)

    I managed to resolve the problem myself. I just added this code before the main loop and everything is working fine.

    <?php query_posts("showposts=14"); ?>

    Thanks for your time.

    Banago

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘WordPress loop counts my featured articles’ loop posts’ is closed to new replies.