您好我正在尝试根据帖子的年龄输出图片。
例如对于循环,我想说:如果帖子的日期小于3天,则在帖子旁边显示高级图标,ELSE,如果帖子超过3天,则显示旁边的常规图标帖子。
提前感谢您的帮助。
<?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; ?>
答案 0 :(得分:0)
尝试使用此语句获取帖子的年龄(以天为单位):
(date('U') - get_post_time('U'))/60/60/24
您可以按如下方式使用它:
<?php if ((date('U') - get_post_time('U'))/60/60/24 <= 3): ?>
<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; ?>