<?php
$categories1=get_categories(\'orderby=post_date&order=DESC\');
function filter_where( $where = \'\' ) {
$today = date(\'Y-m-d\', current_time( \'timestamp\' ));
$yesterday = strtotime ( \'-1 day\' , strtotime ( $today ) ) ;
$yesterday = date(\'Y-m-d\', $yesterday);
$where .= " AND post_date >= \'" . $yesterday . "\'" . " AND post_date < \'" . $today . "\'";
return $where;
}
add_filter(\'posts_where\', \'filter_where\');
foreach($categories1 as $category1) {
$posts=get_posts(\'showposts=1&cat=\'. $category1->term_id);
if ($posts) {
foreach($posts as $post) {
setup_postdata($post);
?>
<li>
<?php the_time(\'F j, Y , g:i a\') ?>
<h6></h6>
<h5 class="l_yellow"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
</li>
<?php }}}
remove_filter(\'posts_where\', \'filter_where\');
wp_reset_query();
?>
我的问题:
今天是7月14日,为什么从7月11日开始出现帖子?我只想知道日期而不是时间。
我有两个类别中的一篇文章,如何只显示一个类别中的一篇文章?
SO网友:stealthyninja
对于第二个问题,下面的代码示例将把帖子的ID添加到数组中,如果它们已经在数组中,则不显示它们:
<?php
foreach($posts as $post) {
setup_postdata($post);
$posts_array[] = get_the_ID();
if ( ! in_array( get_the_ID(), $post_array ) ) {
?>
<li>
<?php the_time(\'F j, Y , g:i a\') ?>
<h6></h6>
<h5 class="l_yellow"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
</li>
<?php
}
// the rest of your code...
?>