WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Double post listing on page

[Resolved] Double post listing on page

  • Hello
    I am using exec-PHP so I’m putting some code directly on the page.

    The problem is that when I put the query_posts of a category on my page, it queris it two times!

    what chould i do?

    This is teh code on the page.php file

    <?php if (have_posts()) : ?>
    
       <?php while (have_posts()) : the_post(); ?>
    
    <div class="postpage" id="post-<?php the_ID(); ?>">

    and the part of code on the page:

    <?php query_posts('cat=12&showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>">
              <?php the_title(); ?></a></li>
          <?php endwhile; ?>

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    @esmi

    Forum Moderator

    I’d guess that’s because you have 2 (nested) Loops – one from the template and one in the content.

    i know, so can I formulate in another way my loop on the page or on the page.php file so it fixes somehow ?

    esmi

    @esmi

    Forum Moderator

    A custom page template that includes your query_posts might be the best way to deal with this. You could just start by copying page.php and replacing the default Loop with your code.

    http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    the solution was to formulate the code in teh page.php like this:

    <?php if (have_posts()) : the_post(); ?>
    
    <div class="postpage" id="post-<?php the_ID(); ?>">

    i have put out the while loop, so now it shows all perfectly.

    Thanks for your time esmi !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Double post listing on page’ is closed to new replies.
Skip to toolbar