2010-09-14 264 views
0

我意識到這個問題可能是主題特定的,但我不知道是否有一個插件。我想隱藏較舊的WordPress帖子的日期(比今年更早)。這裏是我在網上找到的關於這個主題的代碼 - 但我不確定它可以適用於我的特定主題(它應該取代日期代碼)。隱藏日期在舊的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; 
} 

回答

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]'; 
} 

沒有測試尚未...

相關問題