• On my site, http://www.talkingaboutmovies.com, when I add a new post, it also shows the one (or more) before.

    This is the relevant code from home.php:

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=1”); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=2”); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=3”); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

Viewing 10 replies - 1 through 10 (of 10 total)
  • you’ve got three different queries, but they’re all named the same thing. They need to be named differently. or even better, use “showposts=3” and a single query.

    Thread Starter jackson-kelly

    (@jackson-kelly)

    Thannks doodlebee.

    Sorry for the basic coding question but I’m unsure how to code that. I tried the following:

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=2”); query_posts(1); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

    Thanks,

    Jackson

    Thread Starter jackson-kelly

    (@jackson-kelly)

    Sorry, also, where is the query name in the code?

    Jackson

    yeah – that second example is messed up.

    All you have to do is replace your “showposts” with the number of posts you want to show.

    <?php $recent = new WP_Query("cat=1&showposts=3"); if($recent->have_posts()); ?>
    <div class="featured">
    <?php while($recent->have_posts()) : $recent->the_post();?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content('read the story &raquo;');?>
    <?php endwhile; ?>
    </div>
    <?php endif; ?>
    Thread Starter jackson-kelly

    (@jackson-kelly)

    Cool, thanks. I tried that earlier which has the current result of showing the one post per one but it’s showing my most recent post 3 times where there should be 3 different posts. Not sure which part I should be changing to call up the individual posts?

    Okay – huh? Sorry – but that’s worded really weird – I don’t quite understand what you’re saying.

    I’ll try and break this down for you – maybe that’ll help.

    $recent = new WP_Query(“cat=1&showposts=3”);
    This sets up your query. It pulls the most recent 3 posts from the category with the ID of 1.

    if($recent->have_posts());
    this says “If there are posts in category 1…” and begins the Loop.

    while($recent->have_posts()) : $recent->the_post();
    ..then while there are posts in category 1, then display them.

    if it’s showing the same post three times, then my only guess is that you have a double loop going on. Your theme isn’t set up like this is it:

    <?php if(have_posts()): while(have_posts()) : the_post(); ?>
    <?php $recent = new WP_Query("cat=1&showposts=3"); if($recent->have_posts()); ?>
    <div class="featured">
    <?php while($recent->have_posts()) : $recent->the_post();?>
    <h2><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content('read the story &raquo;');?>
    <?php endwhile; ?>
    </div>
    <?php endif; ?>
    <?php endwhile; endif; ?>

    if so, that’s your problem.

    Thread Starter jackson-kelly

    (@jackson-kelly)

    Sorry about the wording. It doesn’t look like it I know but I’ve installed WordPress themes and posted on numerous occasions but this theme’s giving me a headache.

    This is from page.php

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1><?php the_title(); ?></h1>

    <?php the_content(__(‘Read more’));?><div style=”clear:both;”></div>

    <!–
    <?php trackback_rdf(); ?>
    –>

    <?php endwhile; else: ?>

    <p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p><?php endif; ?>

    </div>

    </div>

    <?php include(TEMPLATEPATH.”/sidebar.php”);?>

    </div>

    <!– The main column ends –>

    <?php get_footer(); ?>

    and this is from home.php:

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=1”); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=1”); query_posts(1); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

    <div class=”featured”>
    <?php $recent = new WP_Query(“cat=1&showposts=1”); while($recent->have_posts()) : $recent->the_post();?>
    <h2>” rel=”bookmark”><?php the_title(); ?></h2>
    <?php the_content(__(‘Read the story »’));?><div style=”clear:both;”></div>
    <?php endwhile; ?>
    </div>

    Okay – well form what you’ve shown me, the only thing I can see that’s wrong is what Iv’e said before: all of your queries are named the same thing, which would definitely cause the “repeat” issue. But if you just replace ALL of them with the single query I posted above, it should be working fine. I’ve done it many, many times with no problems. So…I’m not sure what else to offer. Either I need to see the entire “home.php” file (use pastebin! don’t put it here!), or maybe someone else can come along and offer something else.

    Thread Starter jackson-kelly

    (@jackson-kelly)

    Thanks doodlebee, I’ve posted it to pastebin here:
    http://pastebin.com/m2dbdbe1c

    Jackson

    Thread Starter jackson-kelly

    (@jackson-kelly)

    Okay, that’s resolved.
    It’s the category IDs I was having trouble with.
    I’ve installed a plugin to reveal them and now all is well.
    Thanks for all your help,
    Jackson

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

The topic ‘Posts incorporating earlier ones’ is closed to new replies.