• On my main page: https://embedded411.com

    I call our the “Latest Story” then list the 6 most recent stories below it. I do not want the Latest Story to be duplicated. I believe I have to run a query because I call for different fields. For example, the Latest Story calls for a custom image field, while stories 2-7 do not.

    Can someone please tell me what’s wrong with my code? How do I eliminate the duplication of the latest story?

    Latest Story

    <?php query_posts('showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>"><img src="<?php $key="image"; echo get_post_meta($post->ID, $key, true); ?>" border="0" /></a>
    <div id="topstory">
    <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
    <?php the_excerpt(); ?>
    <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
    <?php endwhile; ?>

    Following stories, 2-7 most recent:

    <?php $my_query = new WP_Query('showposts=6');
    if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span class="date"><?php the_time('j M') ?></span><br />
    <span class="catname">Posted in: <?php the_category(', ') ?></span></h4>
    <?php the_excerpt(); ?>
    <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span><br />
    <br />
    <?php endwhile; endif; ?>
Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter dbunit16

    (@dbunit16)

    Please…. anyone?

    Thread Starter dbunit16

    (@dbunit16)

    You are awesome! thank you!

    One more question…

    <?php query_posts(‘category_name=storage&showposts=1&offset=0’);

    I have category_name=storage , how do I can this is that articles will pulled the correct category?

    This one is for my category.php page. So i need it to automatically detect the category.

    Thanks,

    Jon

    The topic, Resetting after multiple loops, hit the wp-hackers list in the last week. Might pay particular attention to Otto’s advice on using new WP_Query.

    Thread Starter dbunit16

    (@dbunit16)

    Let me explain further…

    I have created custom templates for the main categories of my site:

    category-11.php – Blades
    category-16.php – Storage
    etc…

    I used multiple loops on these pages to display the first story differently than the next 5.

    My issue is, on these pages I’m calling out the category here:
    ?php query_posts(‘category_name=storage&showposts=1&offset=0’);

    So that it knows where to pull from.

    Now, I am working on category.php, so that any other categories that don’t have a custom template would use this one. Problem is,
    category_name=storage&showposts=1&offset=0′)

    What would I put there so that it detects the category automatically? If I remove the above bolded part completely, then it draws from all categories, instead of a particular one.

    Hope that’s clearer!

    Thank you!

    I would go about this differently. On your custom category templates i would use the following new WP queries to get your posts. This first section will get your first post from those categories:

    <?php $recent = new WP_Query("category_name=blades&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    
    //do stuff
    
    <?php endwhile; ?>

    Then underneath that lets use the offset function to bring in the next 5.

    <?php $recent = new WP_Query("category_name=blades&showposts=5&offset=1"); while($recent->have_posts()) : $recent->the_post();?>
    
    //do stuff
    
    <?php endwhile; ?>

    Do that both both your custom category templates and then on your category.php template you can just use the normal loop.

    Thread Starter dbunit16

    (@dbunit16)

    Thanks Equal… I still need to do two loops on the normal category page though… and still have the offset 1….

    You might be able to just use the same idea but leave the cateogry_name bit off so you just have ('showposts=1') and then the lower one would have ('showposts=5&offset=1')

    Never done it but worth a try.

    Thread Starter dbunit16

    (@dbunit16)

    Doesn’t seem to work, I just get the most recent posts from all categories… just like the main page…

    so you want to exclude the two categories that have their own templates?

    If so just use the following:

    ('cat=-11,-16&showposts=1') and then below (‘cat=-11,-16&showposts=5&offset=1’)`

    The negatives should prevent those categories from displaying.

    Thread Starter dbunit16

    (@dbunit16)

    would this be valid: (‘showposts=all&offset=6’)

    I want to create a More page that lists the rest of the articles… seems like it might only be showing 1 though… There even though there are 8 articles in the db, so it should show 2…

    Thread Starter dbunit16

    (@dbunit16)

    nevermind! I will just change it to a very large number! *thinking caps work great!* haha

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Excluding the First Post’ is closed to new replies.