【问题标题】:Wordpress set image next new post titleWordpress 设置图像下一个新帖子标题
【发布时间】:2015-01-04 09:40:46
【问题描述】:

我有代码:

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

此代码列出了特定类别的最后 5 个帖子。看起来是这样的:

它还提供发布特定帖子的时间,如上图所示。我想要做的是在帖子旁边有 x 小时/天前的图像,它看起来像这样:

但是即使从我应该开始的地方我也没有想到正确的方法,我也找不到任何接近我需要的东西,也许有人可以从我应该开始的地方给我一个例子?谢谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您可以简单地将帖子的时间戳与您需要的时间进行比较:

    <?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');
        }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      相关资源
      最近更新 更多