Hi I’m trying to output a image based on the age of a post.
For instance with the loop, I want to say: IF the post’s date is younger than 3 days, display the premium icon next to the post, ELSE, IF the post is older than 3 days, display the general icon next to the post.
Thank you in advance for any help.
<?php global $wp_query;
query_posts( array(
'post_type' => 'job_listing' ,
'showposts' => 5 )
); ?>
<?php if ( have_posts() ): ?>
<div class="shortcode post archive grid two-column">
<div class="grid-row linearise">
<div class="grid-item">
<article class="unboxed">
<div class="content">
<div class="typography">
<table style="width:100%">
<tr>
<th>STATUS</th>
<th>JOB TITLE</th>
<th>LOCATION</th>
<th>POSTED</th>
</tr>
<?php while ( have_posts() ) : the_post(); ?>
<tr>
<td class="status">
<?php if ( $postDate < $todaysDate || $postDate == $todaysDate ) { ?>
<img src="<?php bloginfo('template_directory');?>-child/images/icon-premium.png"/>
<?php else: ?>
<img src="<?php bloginfo('template_directory');?>-child/images/icon-general.png"/>
<?php endif; ?>
*</td>
<?php endwhile; ?>
<td><a href="<?php esc_url( the_permalink() ); ?>"><?php the_title(); ?></a></td>
<td><?php the_job_location( false ); ?></td>
<td><span class="datetime"><?php echo get_the_date( "d/m/Y" ); ?></span></td>
</tr>
</table>
<p>*Premium jobs are jobs between 1-3 days old. You can view all of our other jobs at any time.</p>
</div>
</div>
</article>
</div>
<?php if ( have_posts() ): ?>
</div>
</div>
<p><a href="<?php echo site_url(); ?>/jobs" target="_self" class="button small">See all of our jobs</a></p>
<?php endif; ?>
<?php else: ?>
<article class="unboxed">
<div class="content">
<div class="typography">
<p>Alternative Content</p>
</div>
</div>
</article>
<?php endif; ?>
Try using this statement to get the age of the post (in days):
You can use it as follows: