【问题标题】:Hide date in old WordPress posts隐藏旧 WordPress 帖子中的日期
【发布时间】:2010-09-14 03:52:46
【问题描述】:

我意识到这个问题可能是特定于主题的,但我不确定是否有插件。我想隐藏旧 WordPress 帖子的日期(任何比今年更早的帖子)。这是我在网上找到的关于这个主题的代码——但我不确定它是否适用于我的特定主题(它应该替换日期代码)。

01  <?php
02  $today = date('r');
03  $articledate = get_the_time('r');
04  $difference = round((strtotime($today) - strtotime($articledate))/(24*60*60),0);
05  if ($difference >= 30)
06  {
07  ?>
08  <!-- Aged Gem -->
09  <?php
10  } else {?>
11  <!-- Fresh Gem --><strong><?php the_time('F jS, Y') ?></strong>
12  <?php
13  }?>

这是我的 functions.php 中的内容(我正在运行 StudioPress 主题之一)。

add_filter('genesis_post_info', 'post_info_filter');
function post_info_filter($post_info) {
    $post_info = '[post_date] by [post_author_posts_link] at [post_time] [post_comments] [post_edit]';
    return $post_info;
}  

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    将原始add_filter 放入注释中并将此代码添加到您的functions.php:

    add_filter('genesis_post_info', 'post_info_filter2');
    
    function post_info_filter2($post_info) 
    {
        global $post;
    
        // A leap year has 31622400 seconds, but we’ll ignore that.
        $datestring = ( time() - strtotime($post->post_date) > 31536000 )
            ? '' : '[post_date] ';
    
        return $datestring . 'by [post_author_posts_link] at [post_time] [post_comments] [post_edit]';
    }  
    

    还没有测试过……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多