Php 根据wordpress post的年龄显示图像的条件标记

Php 根据wordpress post的年龄显示图像的条件标记,php,wordpress,if-statement,conditional,custom-post-type,Php,Wordpress,If Statement,Conditional,Custom Post Type,嗨,我正在尝试输出一个基于帖子年龄的图像 例如,对于循环,我想说:如果帖子的日期小于3天,则在帖子旁边显示premium图标,否则,如果帖子的日期大于3天,则在帖子旁边显示general图标 提前感谢您的帮助 <?php global $wp_query; query_posts( array( 'post_type' => 'job_listing' , 'showposts' => 5 ) ); ?> <?php if ( have_posts

嗨,我正在尝试输出一个基于帖子年龄的图像

例如,对于循环,我想说:如果帖子的日期小于3天,则在帖子旁边显示premium图标,否则,如果帖子的日期大于3天,则在帖子旁边显示general图标

提前感谢您的帮助

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

*优质工作是指1-3天的工作。您可以随时查看我们的所有其他作业

替代内容


尝试使用此语句获取帖子的发布时间(以天为单位):

您可以按如下方式使用它:

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

-child/images/icon premium.png/>
-child/images/icon-general.png“/>

您能否将代码缩减到所需的最小代码量?因此,您需要帮助的部分被突出显示。这就是答案,感谢您快速准确的回答。太好了!没问题。:)
<?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; ?>