作者列表页面:根据不正确的上次发布日期排除

时间:2013-04-17 作者:Vince Pettit

使用以下代码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 ?>

2 个回复
最合适的回答,由SO网友:tfrommen 整理而成

您可能需要使用以下内容:

if (strtotime(\'-6 months\', time()) >= strtotime($posts[0]->post_date))
    continue;
使用时strtotime, 实际上,您可以用文字进行计算(例如。,+1 month, -3 hours).

SO网友:s_ha_dum

strtotime 会做约会数学。

echo date(\'Y m d\',strtotime(\'-6 months\',time()));
所以你应该可以做一些像。。。

$ptime = strtotime($post->post_date);
$min6m = strtotime(\'-6 months\',time());
if ($ptime <= $min6m) { 
  // echo \'yay\';
  continue;
}

结束

相关推荐

How can i list random author?

Im列出所有作者列表的当前类别,但我想列出当前类别中的随机作者列表。我尝试了“order”=>“RAND”,RAND代码不起作用。我的代码:function getCurrentCatID(){ global $wp_query; if(is_category() || is_single()){ $cat_ID = get_query_var(\'cat\'); } return $cat_ID; } $cu