• There are a few other topics similar but they don’t answer this question:
    How do you group posts together in the loop without the box closing around each one?

    If I put in a tag just after the begining of the loop and just before the end it closes for each post. The closing Tag has to appear and disappear depending on the date.

    I’m trying something different, I’m trying to group the days posts by using the <fieldset> tag and have the date as the <legend> tag. Not too prominent a colour but thats CSS and easy 😉

    Anyway, the best way I can think of to do it is have a conditional tag insertion best possible way I think of is:


    /*** BEGIN THE LOOP ***/

    ...

    <fieldset>
    <legend> <?php the_date(); ?> </legend>

    A BUNCH OF POST CONTENT

    if (date_this_post != date_last_post) {
    </fieldset>
    }

    ...

    /*** END THE LOOP ***/

    Would it be acceptable to create a varible to temporarily store the date to compare to the next post?

    But how detremental to page generation time would that be?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Would it be acceptable to create a varible to temporarily store the date to compare to the next post?

    Sure.

    But how detremental to page generation time would that be?

    One variable set and an “if” to check it? You’d never notice it.

    Thread Starter allstar

    (@allstar)

    I’m new at this so be kind:

    This is my slightly less pseudo code for my loop:

    <?php if (have_posts()) : while (have_posts()) : the_post();

    if ($last_post_date != the_date() ) { ?>
    <fieldset>
    <legend><?php the_date(); ?></legend>
    <?php }
    else {
    } ?>

    <div class="post" id="post-<?php the_ID(); ?>">

    <h3 class="storytitle">" rel="bookmark"><?php the_title(); ?></h3>
    <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> — <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>

    <div class="storycontent"><?php the_content(__('(more...)')); ?></div>

    <div class="feedback">
    <?php wp_link_pages(); ?>
    <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
    </div>

    </div><!-- .post -->

    <?php
    if ( $last_post_date != the_date() ) { ?>
    </fieldset>
    <?php }
    else {
    }

    comments_template(); // Get wp-comments.php template ?>

    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>

    <?php $last_post_date == the_date(); ?>

    <?php endif; ?>

    This puts the date on the page once for all the entries for that date. It does not put the <fieldset> or <legend> tags in the source for the page. I tried using the echo and print function but they didn’t work ( besides escaping the code is more effectient )

    Where am I going wrong?

    Thread Starter allstar

    (@allstar)

    I have found the problem this: <?php $postdate = the_date(); ?>

    Doesn’t store ‘the_date()’ as a varible it merely prints out the date where this is writen thus all the if statements always read $postdate to be empty.

    Full Code:

    <?php $postdate = the_date(); ?>

    <?php
    if ( !empty($postdate) ) { ?>
    <fieldset class="date">
    <legend class="date"><?php the_date(); ?</legend>
    <?php }
    else { ?>
    <b>No Date in Header</b>
    <?php } ?>

    <?php
    if ( !empty($postdate) ) { ?>
    </fieldset>
    <?php }
    else { ?>
    <b>No Date in Footer</b>
    <?php } ?>

    Why won’t the_date(); store as a varible?

    is there a solution on how to store the_date in to a variable?

    I used a “control” post and get_the_time. More here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Group By Articles Date’ is closed to new replies.