WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Double post listing on page (5 posts)

  1. eian00
    Member
    Posted 4 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 4 years ago #

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

  3. eian00
    Member
    Posted 4 years ago #

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

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    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

  5. eian00
    Member
    Posted 4 years ago #

    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 !

Topic Closed

This topic has been closed to new replies.

About this Topic