0

Im trying to have 5 posts for page in my blog. This is what Ive used in index.php

<?php
    get_header();
    query_posts('posts_per_page=5');

    // The Loop
    if (have_posts()){

        while (have_posts()){

            //Iterate the cursor on the next post
            the_post();

            echo "<a class='more-link' href='";
            the_permalink();
            echo "'><h1>";
            the_title();
            echo "</h1></a>";

            echo "<div class='meta'>";
            the_date();
            echo "&nbsp;&nbsp;|&nbsp;&nbsp;";
            comments_number();
            echo "</div>";

            echo "<a class='more-link' href='";
            the_permalink();
            echo "'>";
            the_post_thumbnail();
            echo "</a>";

            the_excerpt();
            echo "<a class='more-link' href='";
            the_permalink();
            echo "'>Continue reading</a>";

            echo "<hr>";
        }
    }

    get_footer();
?>

I want to put a link at the bottom for "show older posts", but I dont know how should I alter the file to do this. Any idea, please? Thank you

  • Your loop ends at the file footer.php - can you paste that one too? – Sagive SEO Apr 3 '12 at 19:37
  • There no additional PHP code, just closing tags </body></htm> – Enrique Moreno Tent Apr 3 '12 at 19:45
1

Ok then... try this (hope i got your request right):

REVISED

<?php
    get_header();
    query_posts( array(
          'posts_per_page' => 5,
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
     ));

    // The Loop
    if (have_posts()){

        while (have_posts()){

            //Iterate the cursor on the next post
            the_post();

            echo "<a class='more-link' href='";
            the_permalink();
            echo "'><h1>";
            the_title();
            echo "</h1></a>";

            echo "<div class='meta'>";
            the_date();
            echo "&nbsp;&nbsp;|&nbsp;&nbsp;";
            comments_number();
            echo "</div>";

            echo "<a class='more-link' href='";
            the_permalink();
            echo "'>";
            the_post_thumbnail();
            echo "</a>";

            the_excerpt();
            echo "<a class='more-link' href='";
            the_permalink();
            echo "'>Continue reading</a>";

            echo "<hr>";
        }
    }
    ?>
    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
    </div>
    <?php get_footer(); ?>

.

Hope this helps,
Cheers, Sagive.

  • Thats not what I mean. What I want is a link to the list of the NEXT 5 older posts. With that I will only see the 6th newest post. – Enrique Moreno Tent Apr 3 '12 at 21:41
  • 1
    Aplogies.. didnt see that query at the head of your loop, try it now.. – Sagive SEO Apr 3 '12 at 22:08
  • Exactly what I wanted! I didnt know the "paged" option. Million thanks ;) – Enrique Moreno Tent Apr 3 '12 at 22:18
  • My pleasure mate ;) – Sagive SEO Apr 3 '12 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.