Forums

Archives and Recent Entries (3 posts)

  1. kwarrior
    Member
    Posted 6 years ago #

    I have a two questions that I couldn't find answers to on the Codex:

    • What is the best way to link to an "archives" page? Not something like wp/2005 or wp/2005/08 (included , but something like wp/archives that will list by month or by category. Would you recommend I create my own page out of that? I've seen the archives template page. I can just use that for one of my pages and name it archives, but is that the best way to do it?
    • How do I create a "recent entries" section for my sidebar? Right now I have:

      <?php for ($recent_posts_count = 0; have_posts() && $recent_posts_count < 5; $recent_posts_count++) : the_post(); ?>
      //display excerpt
      <?php endfor; ?>

      The problem is, archives.php already looped through all the posts, so have_posts becomes false. I did it this way because my index.php only displays the first (most recent?) post, so that the recent section will display the rest of them. Is there a way to reset the post list?

  2. Kafkaesqui
    Moderator
    Posted 6 years ago #

    Q1: There are a number of ways to set up an archives Page in WordPress. Some info on it can be found here:

    http://codex.wordpress.org/Creating_an_Archive_Index

    Q2: For that you need call a new query object to *initialize* your custom loop. See the info on setting up multiple loops:

    http://codex.wordpress.org/The_Loop#Multiple_Loops

    Focus on the info covering WP_Query(). Let us know if you get lost there...

  3. kwarrior
    Member
    Posted 6 years ago #

    Thank you. FYI, I ended up using rewind_posts(), because I didn't really need a "custom" loop, rather just another loop.

Topic Closed

This topic has been closed to new replies.

About this Topic