• I am using Glider in a project for a client – see here: https://intunedonline.com.netfirms.com/. This involves using multipe posts multiple loops. Please find below the codes

    This is used to display 5 featured posts

    <?php $count = 1 ?>
    <?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 echo $count; ?>
    <?php $count = $count + 1 ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt() ?>
    <?php endwhile; ?>

    This is used to display 5 anchor links to the firs 5 featured posts based on the id

    <?php $count = 1 ?>
    <?php $my_query = new WP_Query('category_name=featured&showposts=5');
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li><a href="#section<?php the_ID(); ?>" rel="nofollow"><?php echo $count; ?></a></li>
    <?php $count = $count + 1 ?>
    <?php endwhile; ?>

    This is the normal loop that must (BUT DOES NOT) display the other posts expect the above ones.

    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate[$post->ID] ) continue; ?>
    
    <div class="<?php echo $odd_or_even; ?>" id="post-<?php the_ID(); ?>">
    <?php $odd_or_even = ('odd'==$odd_or_even) ? 'even' : 'odd'; ?>
    
    <div class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
    <?php the_excerpt(); ?>
    </div>
    <?php endwhile; endif; ?>

    The problem is that this does not continue showing the rest of the posts. It just goes on showing only 4 posts.

    How do I have to alter the code so that I have 10 other posts displayed in the home page?

    Thanks very much!

    Baki

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    You’re doing it wrong to start with.

    Define what you want to happen. Then we’ll tell you how to do it.

    Right now, here’s what you have:
    1. Pull and display 5 posts from featured category. Save their ID’s.
    2. Pull and display same 5 posts from featured category. Show their links.
    3. Pull and display latest 10 posts from any category. Show them, unless they were one of the first five, in which case skip them.

    That’s what you have now. It’s flawed in two major ways I can see:
    a) Step 2 is unnecessary since you could have just saved the links from the first Loop and displayed them later on, saving much database work.
    b) You’re pulling 10 posts in the second loop, but 10 posts of all kinds. So you’ll get less than 10 showing if any of them are those that already displayed in the first Loop.

    Define what you want to happen, in English. Then we’ll tell you how to do it the right way.

    Thread Starter banago

    (@banago)

    You’re pulling 10 posts in the second loop, but 10 posts of all kinds. So you’ll get less than 10 showing if any of them are those that already displayed in the first Loop.

    This does not happen even though the code seems alight.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Okay, I said “10” but that assumes that you have the number of posts to display on the Settings page set to 10. If you have it set to something else, then you’ll get a different number.

    Thread Starter banago

    (@banago)

    Yes, I have set them to 9 (but saying 10 just to illustrate). If you click older posts, they will display OK, but in the font page id does not and this is what I do not understand.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘$my_query = new WP_Query(‘cat=10&showposts=5’)’ is closed to new replies.