dongxinche1264 2015-01-04 01:18
浏览 36
已采纳

Wordpress设置图像下一个新帖子标题

I have code:

    <div id="content88">
<div class="tip">
<div style="margin-left: 9%; margin-top: -2px;">
<center><h1><font style="margin-left:-50px;" font-size="20px" color="#BCBDC1">Last 5 posts from category</font></h1></center></p>
<?php
$catquery = new WP_Query( 'cat=11446&posts_per_page=5' );
while($catquery->have_posts()) : $catquery->the_post();
?>

<h4><a href="<?php the_permalink() ?>" rel="bookmark"><font color="#fff"><?php the_title(); ?></font></a> - <b>Last update:</b>  <span class="entry-date"><?php echo the_modified_time('Y/m/d \a\t g:i A'); ?></span> </h4> </p>

<?php endwhile; ?>
<center><h4><a href="#"><font style="margin-left:-50px;" font-size="14px" color="#BCBDC1">Click here for more results</font></a></h4></center></p>
</div>
</div>
</div>

This code lists last 5 posts from specific category. It looks like that:

Click to view image

It also delivers the time when the specific post was posted as you can see from the image above. What i want to do is have image next to posts which is x hours/days old that it would look like this:

Click to view image

But i fail to think proper way to do it even from what i should start, also i failed to find anything near what i need, maybe somebody could give me even example from what i should start? Thanks.

  • 写回答

1条回答 默认 最新

  • douchun5969 2015-01-04 01:40
    关注

    You can simply compare the timestamps of your post with the time you need:

    <?php
        $olderThanTime = strtotime('-2 hours');
        $postTime      = strtotime(get_the_time('Y-m-d H:i:s', get_the_ID()));
    
        if ($postTime > $olderThanTime ) {
            the_post_thumbnail('small');
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理