如何显示过期帖子列表

问题描述 投票:0回答:1

我尝试使用以下代码不通过自定义字段按日期显示过期的帖子。到目前为止,它有效,帖子超出了类别。现在如何只显示过期的帖子?

参考:http://debbieteakle.com/2011/11/add-an-expiry-date-to-wordpress-posts

<?php query_posts('cat=4,1'); ?> //my custom query for categories 4 & 1
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- expiry code below -->
 <?php
    $currentdate = date("Ymd");
    $expirationdate = get_post_custom_values('expiration');
    if (is_null($expirationdate)) {
    $expirestring = '30001212'; //Set future date to posts with expiry.
    } else {
     if (is_array($expirationdate)) {
    $expirestringarray = implode($expirationdate);
    }
    $expirestring = str_replace("/","",$expirestringarray);
    } //else
    if ( $expirestring > $currentdate ) { ?>
<!--end expiry code-->
 <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<!-- thumbnail code below -->
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php } else { ?>
<?php } ?>
<!--end thumbnail code-->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to
<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p>Posted on <?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p>
<!-- shows excerpts below -->
<?php
global $more;
$more = 0;
?>
<!-- end shows excerpts code -->
<?php the_content('Read the rest of this entry &raquo;'); ?>
<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> |
<?php edit_post_link('Edit'); ?>  </p>
</div>
<?php } ?>
<?php endwhile; endif; ?>
php wordpress
1个回答
0
投票

在 if 条件下将大于运算符

<
更改为小于运算符
>
。你的代码应该是这样的。

if ( $expirestring < $currentdate ) { ?>

它只会显示过期的帖子。

© www.soinside.com 2019 - 2024. All rights reserved.