我一直在寻找一种方法来按日期限制 wordpress 标签,并根据它们在选定时间范围内出现的次数对它们进行排序。但我一直很不成功。
我想要达到的目标类似于 Twitter 上的热门话题。但在这种情况下,“趋势标签”。默认情况下,wordpress tagcloud 显示有史以来最流行的标签。这对我来说没有意义,因为我想跟踪当前的趋势。
理想情况下,它应该是这样的:
当今最流行的标签
然后乘以“本周最受欢迎”和“本月最受欢迎”。有谁知道实现这一目标的方法?
最佳答案
好的,所以我认为您可能想要这样做,例如最近 50 个帖子。
循环上一个 n
帖子,提取term_id
每个帖子的每个标签,然后将该字符串传递到 include
wp_tag_cloud()
的论据;
$how_many_posts = 50;
$args = array(
'posts_per_page' => $how_many_posts,
'orderby' => 'date',
'order' => 'DESC',
);
// get the last $how_many_posts, which we will loop over
// and gather the tags of
query_posts($args);
//
$temp_ids = array();
while (have_posts()) : the_post();
// get tags for each post
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
// store each tag id value
$temp_ids[] = $tag->term_id;
}
}
endwhile;
// we're done with that loop, so we need to reset the query now
wp_reset_query();
$id_string = implode(',', array_unique($temp_ids));
// These are the params I use, you'll want to adjust the args
// to suit the look you want
$args = array(
'smallest' => 10,
'largest' => 30,
'unit' => 'px',
'number' => 150,
'format' => 'flat',
'separator' => "\n",
'orderby' => 'count',
'order' => 'DESC',
'include' => $id_string, // only include stored ids
'link' => 'view',
'echo' => true,
);
wp_tag_cloud( $args );
关于wordpress - 如何按日期限制wordpress tagcloud?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2941251/