1

我已经为艺术品建立了一个 wordpress 网站,并希望对其进行设置,以便我可以在管理员中创建一个用户可以选择的自定义字段,并将在前端显示“新”。创建它非常简单,但我想“新”在三十天后过期。任何有关设置到期部分的想法将不胜感激。

4

1 回答 1

1

假设您当前有一个自定义帖子类型存档模板(默认情况下,如果您的自定义帖子类型被命名为“艺术品”,那么archive-artwork.php您可以使用如下函数创建一个检查它的发布日期the_date()

// expiration date is a rolling date from 30 days ago
$expiration_date = date('Ymd', strtotime("-30 days"));

// use the_date( $format, $before, $after, $echo ) to get the current post's
// date in the loop
$post_date = the_date('Ymd', '', '', false);

// compare the dates and output different markup or classes to your HTML
if ($post_date < $expiration_date) {
    echo '<div class="expired-post">';
}
else {
    echo '<div class="new-post">';
}
于 2013-07-26T22:36:05.343 回答