WordPress.org

Ready to get started?Download WordPress

Forums

Help with Multiple Loops in Index Page (4 posts)

  1. lqunta
    Member
    Posted 3 years ago #

    Greetings All,

    I'm a newbie trying to code a custom structure for my index.php page [ for the default home page ] in wordpress. So far, I've tried various approaches but don't seem to be making any progress [ my page just shows up as blank when tested ].

    In a nutshell, I'm trying to achieve the following structure

    - Header = (Logo, Search Form) + (Navigation)
    - Leader Board = (Text Widget + Posts Slideshow {smoothgallery})
    - Content = Row 1 ( Category Title + Brief Description (Hard Coded in HTML) + 4 Most Recent Posts { Post Title Permalink, Post Thumbnail, Post Excerpt } ) + ( Category Title + Brief Description (Hard Coded in HTML) + 4 Most Recent Posts { Post Title Permalink, Post Thumbnail, Post Excerpt } ) + ( Category Title + Brief Description (Hard Coded in HTML) + 4 Most Recent Posts { Post Title Permalink, Post Thumbnail, Post Excerpt } )
    - Footer

    With the above layout, it is evident that I have to use multiple loops for the Category-Posts lists.

    Could someone please help out with the multiple loops [ where possible, a working code would be super :P ] for the content section, I'm desperate.

    Cheers

  2. Taylor Dewey
    Member
    Posted 3 years ago #

    While there may be multiple ways to do this, I have always resorted to creating my own custom loop for things that aren't part of the "main blog." I use this article on weblogtoolscollection to guide me each time. Here is there example code:

    <h3>Recent Articles</h3>
    <ul>
    <?php
        $recentPosts = new WP_Query();
        $recentPosts->query('showposts=5');
    ?>
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
  3. lqunta
    Member
    Posted 3 years ago #

    @Taylorde,

    Thanks for the loop code...quick question: Can I use the same loop multiple times on the same page? In my earlier question, I want to use the loop 3 times [ for the three different category column blocks in the same content area ]

    Cheers

  4. Taylor Dewey
    Member
    Posted 3 years ago #

    Yeah, you can create as many as you want. I typically rename the $recentPosts variable to something that is topical.

Topic Closed

This topic has been closed to new replies.

About this Topic