• The date does not appear AT ALL on my posts created with this code:

    <?php query_posts(‘category_name=Featured Photo&showposts=1’); ?>
    <?php while (have_posts()): the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <p style=”color: #ffffff; font-family: tahoma, geneva; font-size: 10pt; margin-left: 30px;”><?php the_content(); ?></p>
    <p style=”color: #ffffff; font-family: tahoma, geneva; font-size: 10pt; margin-left: 20px;”>Posted by <?php the_author(); ?> on <?php the_date(); ?></p>
    <?php endwhile; ?>

    Funny thing is, I use the EXACT same code earlier in the page, and it works perfectly there, I copied it to a different div, changed the “category_name” and now no date appears whatsoever.

    Any help is greatly appreciated!

Viewing 7 replies - 1 through 7 (of 7 total)
  • isn’t your loop incomplete?

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

    romanonly,

    Try what ryans149 suggests but don’t forget to end the if statement.

    <?php query_posts('showposts=3&cat=6');
    if(have_posts()) : while(have_posts()) : the_post(); ?>
    
    <?php endwhile; endif; ?>
    Thread Starter romanonly

    (@romanonly)

    doc4 and ryans149,

    I tried adding the if and endif statements but I’m still not getting a date. This is actually the SECOND loop in the document, being exactly identical, other than calling a different category and using slightly different formatting. Here’s what the code looks like right now including BOTH of the loops:

    <div class="news">
        <div class="divtitle">
         <h2>News</h2>
        </div>
    
        <br />
    
        <?php query_posts('category_name=News&showposts=1'); ?>
        <?php if (have_posts()) : ?>
        <?php while (have_posts()): the_post(); ?>
    
        <h3><?php the_title(); ?></h3>
        <div style="font-family: tahoma, geneva; color: #ffffff; font-size: 15px; margin-left: 20px;">
        <?php the_content(); ?>
        </div>
        <hr width=95%" size="1" color="#ffffff" align="center">
        <p style="font-family: tahoma, geneva; color: #ffffff; font-size: 12px; margin-left: 20px;">Posted by <?php the_author(); ?> on <?php the_date(); ?>.</p>
    
        <?php endwhile; endif ?>
    
       </div>
    
       <div class="featphoto">
        <div class="divtitle">
         <h2>Featured Photo</h2>
        </div>
    
        <?php query_posts('category_name=featphoto&showposts=1'); ?>
        <?php if (have_posts()) : ?>
        <?php while (have_posts()): the_post(); ?>
    
        <h2><?php the_title(); ?></h2>
        <div style="text-align: center;">
        <?php the_content(); ?>
        </div>
        <p style="font-family: tahoma, geneva; color: #ffffff; font-size: 10px; margin-left: 20px;">Uploaded by <?php the_author(); ?> on <?php the_date(); ?>.</p>
    
        <?php endwhile; endif; ?>
    
       </div>

    The date appears properly in the first loop, but the second loop simply inserts a blank where the date should be.

    Thanks for your help!

    Try using the_time(). the_date() will only show the same date once on a page.

    romanonly,

    greenshady has a good point here: 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.

    Check out the WordPress Template Tag Page for more. https://codex.www.ads-software.com/Template_Tags/the_date

    Thread Starter romanonly

    (@romanonly)

    greenshady and doc4,

    Thank you so much for your help, switching to the_time() solved the problem and the date is appearing perfectly now!

    Awesome!

    Great, this post helped me out! Thank you greenshady. the_date() was driving me nuts.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘the_date() is not appearing on my posts.’ is closed to new replies.