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.
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?
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.