• Resolved eian00

    (@eian00)


    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)
  • I’d guess that’s because you have 2 (nested) Loops – one from the template and one in the content.

    Thread Starter eian00

    (@eian00)

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

    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.

    https://codex.www.ads-software.com/Pages#Creating_Your_Own_Page_Templates

    Thread Starter eian00

    (@eian00)

    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 ‘Double post listing on page’ is closed to new replies.