• Resolved Jeff

    (@jmf)


    I’m making my first site that uses multiple loops on one page, and I’m scratching my head over something. It’s tiny, I believe, and if someone can help me along, I should have smooth sailing from here on out. ??

    The site, for reference, is at https://www.rchseaglesnest.org.

    So, far, I’m working with a ‘Features’ section, and an ‘Around School’ section that correspond to WP categories of the same name.

    The ‘Features’ section should show one post, and then about 5 post tiles in a ‘Recently Featured’ list.

    The ‘Around School’ section should show around 5 posts.

    The loops I’m using look like this:

    (Features section)

    <div id="features">
      <div id="feature-story">
        <?php $temp_query = $wp_query; ?>
        <?php query_posts('category_name=feature&showposts=1'); ?>
        <?php while (have_posts()) : the_post(); ?>
            <h3 class="feature-headline"><?php the_title(); ?></h3>
            <p class="byline">By <span class="allcaps"><?php the_author(); ?></span>
            <p class="the-date"><span class="story-date"><?php the_date('D M j, Y')?></span>&mdash;&nbsp;
            <?php the_content('Read more...'); ?>
        <?php endwhile; ?>
      </div><!-- #feature-story -->
    
      <div id="recent-features">
        <h3 class="subhead">Recently Featured Stories</h3>
        <ul>
            <?php $posts = get_posts('category_name=feature&numberposts=5&offset=1');
        foreach ($posts as $post) : start_wp(); ?>
            <li><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></li>
            <?php endforeach; ?>
        </ul>
      </div><!-- recent-features -->
    </div><!-- #features -->

    (Around School section)

    <div id="around-school">
      <h3 class="subhead">Around School</h3>
      <?php $temp_query = $wp_query; ?>
      <?php query_posts('category_name=around-school&showposts=4'); ?>
      <?php while (have_posts()) : the_post(); ?>
        <div class="article">
            <h3 class="med-headline"><?php the_title(); ?></h3>
            <p class="byline">By <span class="allcaps"><?php the_author(); ?></span>
            <div class="story">
            <p class="the-date"><span class="story-date"><?php the_date('D M j, Y')?></span>&mdash;&nbsp;
            <?php the_content('Read more...'); ?>
            </div>
        </div>
      <?php endwhile; ?>
    </div><!-- #around-school -->

    The posts show up as expected in each section. The list of ‘Recently Featured’ post titles, though, includes titles from ALL categories, and not just the ‘feature’ category.

    Also, for some reason the_date() is coming up empty in the ‘About School’ section. That’s puzzling.

    I’m pretty sure I’m not understanding some fundamental bit about the mechanics of including multiple loops, but I’m not quite sure what I’m slipping up on.

    Could anyone explain this to me?

    Thanks,
    Jeff.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Jeff

    (@jmf)

    Strike: Features –>
    After careful consideration, it appears that get_posts() doesn’t take a ‘category_name’ argument. A category number works swell, though.

    Still stumped on the ‘Around School’ section, though. ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Also, for some reason the_date() is coming up empty in the ‘About School’ section. That’s puzzling.

    From: https://codex.www.ads-software.com/Template_Tags/the_date

    SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() with a date-specific format string.

    Thread Starter Jeff

    (@jmf)

    Aw, man. Thanks, I should’ve noticed that. Everything seems to be working now!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘A little multiple-loop confusion’ is closed to new replies.