WordPress.org

Forums

Custom WordPress Loop (4 posts)

  1. GuruXL
    Member
    Posted 5 years ago #

    Hello. I am looking to create a custom loop for my homepage and then subsequent page on my site.

    My idea is this:

    Homepage
    - Custom Static HTML
    - Recent Post Grouped by Month
    -- January 2010 (Post 1, Post 2)
    -- February 2010 (Post 1, Post 2)
    --- Limit to last 5 posts

    Pages
    - Regular WordPress Loop

    What is the best way to accomplish this using index.php, home.php, page.php and single.php?

    index.php

    <?php
    get_header();
    wp_reset_query();
    if (is_home()) {
      include (TEMPLATEPATH . '/home.php');
    } else { ?>
            <div id="page">
              <div class="two-thirds">
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                  <?php the_content(); ?>
                <?php endforeach; else: ?>
                  <p><?php _e('Sorry, no content matched your criteria.'); ?></p>
                <?php endif; } ?>
              </div>
              <div class="one-third">
    <?php get_sidebar(); ?>
              </div>
            </div>
    <?php get_footer(); ?>

    home.php

    <div class="one-third">
                <h2>Recent News</h2>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <h3><?php the_time('F Y'); ?></h3>
                <p id="post-<?php the_ID(); ?> class="news-item"><span class="news-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></span> <?php the_content('Read More...'); ?></p>
                <?php endwhile; ?>
                <?php else : ?>
                <h3><?php date("F Y"); ?></h3>
                <p>No recent updates...</p>
              </div>
              <?php endif;  ?>
            </div>
    <?php get_footer(); ?>

    Does this make sense?

  2. GuruXL
    Member
    Posted 5 years ago #

    No ideas?

  3. Shane G.
    Member
    Posted 5 years ago #

    Hi,

    Check with this article:

    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    Thanks,

    Shane G.

  4. GuruXL
    Member
    Posted 5 years ago #

    Shane,

    That seems pretty complicated for my purposes. I'll see if there is a simply method to incorporate the information.

Topic Closed

This topic has been closed to new replies.

About this Topic