我尝试了几个不同的循环来显示过去30天浏览量最大的帖子。然而,它只是显示了30 dasy之前的帖子。从过去30天开始就没有了。不是最受欢迎的。如果有人能帮我。太棒了,谢谢=)
这是我目前的循环:
<ul>
<?php
function filter_where($where = \'\') {
//posts in the last 30 days
$where .= " AND post_date > \'" . date(\'Y-m-d\', strtotime(\'-30 days\')) . "\'";
return $where;
}
add_filter(\'posts_where\', \'filter_where\');
query_posts(\'post_type=post&posts_per_page=3&orderby=post_views_count&order=ASC\');
while (have_posts()): the_post(); ?>
<li><div class="tabber-image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(\'small-thumb\'); ?></a>
</div>
<div class="tabber-text">
<?php
//$meta = get_post_meta(get_the_ID());
//$short_title = $meta[\'maxmag_featured_headline\'][0];
?>
<a href="<?php the_permalink() ?>" class="main-headline"><?php the_title(); ?></a></li>
<?php
endwhile;
wp_reset_query();
?>
</ul>
任何帮助都是惊人的。谢谢你抽出时间
编辑---
最后一个循环:
<ul>
<?php while (have_posts()) : the_post();
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 3,
\'meta_key\' => \'post_views_count\',
\'orderby\' => \'meta_value_num\',
\'order\'=> \'ASC\',
\'date_query\' => array(
array(
\'after\' => \'30 days ago\'
),
),
);
$query = new WP_Query( $args );
?>
<li>
<div class="tabber-image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(\'small-thumb\'); ?></a>
</div>
<div class="tabber-text">
<?php
//$meta = get_post_meta(get_the_ID());
//$short_title = $meta[\'maxmag_featured_headline\'][0];
?>
<a href="<?php the_permalink() ?>" class="main-headline"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
插件的原始代码:
<div id="tab2" class="tabber-content">
<?php $popular_posts = new WP_Query(\'showposts=\' . $popular_number . \'&orderby=comment_count&order=DESC\'); if($popular_posts->have_posts()): ?>
<ul>
<?php while($popular_posts->have_posts()): $popular_posts->the_post(); ?>
<li>
<div class="tabber-image">
<?php if ( (function_exists(\'has_post_thumbnail\')) && (has_post_thumbnail()) ) { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(\'small-thumb\'); ?></a>
<?php } ?>
</div>
<div class="tabber-text">
<a href="<?php the_permalink() ?>" class="main-headline"><?php the_title(); ?></a>
<p><?php echo excerpt(10); ?></p>
<div class="headlines-info">
<ul class="headlines-info">
<li>Posted <?php echo human_time_diff(get_the_time(\'U\'), current_time(\'timestamp\')) . \' ago\'; ?></li>
<li class="comments-icon"><a href="<?php comments_link(); ?>"><?php comments_number( \'0\', \'1\', \'%\' ); ?></a></li>
</ul>
</div><!--headlines-info-->
</div>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div><!--tab2-->
SO网友:Saurabh Shukla
尝试以下操作:
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 3,
\'meta_key\' => \'post_views_count\',
\'orderby\' => \'meta_value_num\',
\'order\'=> \'ASC\',
\'date_query\' => array(
array(
\'after\' => \'30 days ago\'
),
),
);
$query = new WP_Query( $args );
您不能直接按met\\U键的名称订购,您需要按照上面的方式使用它。