我尝试使用以下代码,不按日期通过自定义字段显示过期帖子。到目前为止它起作用了,这些帖子不属于类别。现在我如何只显示已过期的帖子?
参考: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 »'); ?>
<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> |
<?php edit_post_link('Edit'); ?> </p>
</div>
<?php } ?>
<?php endwhile; endif; ?>
答案 0 :(得分:0)
如果条件允许,则将大于运算符<
的值更改为小于运算符>
。你的代码应该是这样的。
if ( $expirestring < $currentdate ) { ?>
它只显示已过期的帖子。