wordpress - 如何按日期限制wordpress tagcloud?

标签 wordpress date tags limit

我一直在寻找一种方法来按日期限制 wordpress 标签,并根据它们在选定时间范围内出现的次数对它们进行排序。但我一直很不成功。

我想要达到的目标类似于 Twitter 上的热门话题。但在这种情况下,“趋势标签”。默认情况下,wordpress tagcloud 显示有史以来最流行的标签。这对我来说没有意义,因为我想跟踪当前的趋势。

理想情况下,它应该是这样的:

当今最流行的标签

  • 奥巴马(18 次提及)
  • 纽约(提及 15 次)
  • 钢铁侠(11 次提及)
  • 罗宾汉(7 次提及)

  • 然后乘以“本周最受欢迎”和“本月最受欢迎”。有谁知道实现这一目标的方法?

    最佳答案

    好的,所以我认为您可能想要这样做,例如最近 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/

    相关文章:

    javascript - Js 覆盖源代码中的超链接(W3Layouts 的 Cubicle 模板)

    javascript - 使用 jQuery 将标签插入框中?

    php - 使用 $wpdb 作为 WordPress meta_query 的替代品

    wordpress - ssl 在我的 wordpress 网站的 2 个页面中不起作用

    Python 使用数据/时间作为 x 轴?

    java - 需要帮助将字符串解析为日期

    javascript - 使用不带 <> 的 HTML

    php - 在 Wordpress 循环之外获取发布信息

    php - 在开源 php 照片库和-或 cms 之间进行选择

    mysql - SQLSTATE[42000] : Syntax error or access violation: 1064 You have an error in your SQL syntax;