使用以下代码from this post 我想我已经找到了向过去6个月发帖的作者展示问题的答案。不幸的是,该函数检查日期的方式似乎只阻塞了几个月,没有考虑到前几年,因为它仍然显示较老的帖子/作者。
我认为问题在于if (6 < (date(\'n\',(time() - strtotime($posts[0]->post_date)))))
使用n
是月份。
是否有人可以帮助更正查找,使其仅显示过去6个月的内容?
<?php
// Arguments to pass to get_users
// ************* $args = array( \'orderby\' => \'post_count\', \'order\' => \'DSC\', \'who\' => \'authors\' );
// Query for the users
$authors = get_users(\'orderby=post_count&order=DSC\'); //&role=contributor ?>
<?php
// Loop through all the users, printing all of their posts as we go
foreach ( $authors as $author ) {
// Set up a Loop, querying for all of the current user\'s posts
$args = array( \'author\' => $author->ID, \'posts_per_page\' => 1 );
$posts = query_posts($args);
if (6 < (date(\'n\',(time() - strtotime($posts[0]->post_date)))))
continue; //skips this autor as long as his last post is older than 6 months, be aware that this check uses date function.
?>
<a name="<?php echo $author->user_nicename; ?>"></a>
<div class="author-posts-wrapper" id="author-<?php echo $author->ID; ?>-posts-wrapper">
<div class="author-avatar" id="author-<?php echo $author->ID; ?>-avatar">
<?php echo get_avatar( $author->ID, 96 ); ?>
</div>
<div class="author-posts" id="author-<?php echo $author->ID; ?>-posts">
<h2><a href="<?php echo get_author_posts_url( $author->ID ); ?>"><?php echo $author->display_name; ?></a></h2>
<?php if ( have_posts() ) : ?>
<div class="author-post-list" id="author-<?php echo $author->ID; ?>-post-list">
<?php while ( have_posts() ) : the_post(); // Print whatever we want for each post - for now the title ?>
<div class="author-descrip" style="padding-bottom:2px;">
<?php the_author_meta("description"); ?></div><br />
<p><strong>Most recent article: </strong><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
<p>
<?php if(get_the_author_meta(\'user_url\')): ?>
<?= get_the_author_meta(\'user_url\') ?>
<?php endif; ?>
</p>
<?php endwhile; ?>
</div><!-- #author-post-list -->
<?php else: ?>
<p style="font-style:italic;">This author has not yet published any posts</p>
<?php endif; ?>
</div><!-- #author-posts -->
</div><!-- #author-posts-wrapper -->
<?php } // End looping over all users ?>