• Ski Freak

    (@ski-freak)


    Below is the code I am using.
    The problem I am getting is that the date call in the second block does not return any data.
    Can anyone tell what I am doing wrong?

    <?php  query_posts('posts_per_page=1&category_name=Cat1'); ?>
    <?php  if (have_posts()) : the_post(); ?>
    	<div class="widget latest-post">
    		<span class="latest-title">Latest Cat 1 Post</span><br />
    		<span class="date"><?php the_date(); ?></span><br />
    		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    		<?php the_excerpt(); ?>
    	</div> <!-- END Latest Posts -->
    <?php
    	endif;
    	wp_reset_query();
    ?>
    
    <?php  query_posts('posts_per_page=1&category_name=Cat2'); ?>
    <?php  if (have_posts()) : the_post(); ?>
    	<div class="widget latest-post">
    		<span class="latest-title">Latest Cat 2 Post</span><br />
    		<span class="date"><?php the_date(); ?></span><br />
    		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    		<?php the_excerpt(); ?>
    	</div> <!-- END Latest Posts -->
    <?php
    	endif;
    	wp_reset_query();
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    (@alchymyth)

    that the date call in the second block does not return any data.

    this is one of the peculiarities of the_date() as explained in here:

    http://codex.wordpress.org/Function_Reference/the_date

    Thread Starter Ski Freak

    (@ski-freak)

    Thanks for the quick response…

    I have tried, and failed, using get_the_date()
    How would I use this in the code above?

    Michael

    (@alchymyth)

    i would try to replace:
    <?php the_date(); ?>
    with
    <?php echo get_the_date(); ?>

    Thread Starter Ski Freak

    (@ski-freak)

    Thanks for the suggestion but that does not cater for the dates of the posts being different.
    The code below works, but this is ugly code as far as I am concerned.
    I am open to suggestions for a better way of doing this.
    First block:
    <span class="date"><?php $postDate = the_date(); ?></span><br />
    Second block:
    <span class="date"><?php echo ($postDate == "") ? get_the_date(): the_date(); ?></span><br />

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Problem using query_posts()’ is closed to new replies.