开发者

Compare post dates in WordPress

I'm trying to add a class to an HTML tag depending on the date of the WordPress post. So far I have the code:

while ($recentPosts -> have_posts()) : 
    $recentPosts -> the_post();    
    if (strtotime(the_date('', '', '', false)) > strtotime('-14 days')) {
        echo '<h5 class="new">';
    }
    else {
        echo '<h5>';
开发者_Go百科    }
    the_date();
endwhile;

The class is working great, but the problem I'm having is that the date will not show up after the h5 tag. Not sure what I'm missing or doing wrong.

Phil


The problem seems to be that you're calling the_date() twice... try using get_the_date($postId) or storing the_date() on your line 2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜