首页 问答 正文

WordPress中的热门标签插件有哪些?

注册会员 / 悠然自学 / 2023-06-11/ 浏览 134 次

  1. Tags Widget for WordPress: 这个插件可以在侧边栏中显示热门标签,通过可定制的选项,可以设定标签的个数、排序方式、字体大小和颜色等。
<?php
//在主题中显示标签云
$args = array(
  'smallest'                  => 8, 
  'largest'                   => 22,
  'unit'                      => 'pt',
  'number'                    => 45,
  'format'                    => 'flat',
  'separator'                 => "n",
  'orderby'                   => 'name', 
  'order'                     => 'ASC',
  'exclude'                   => null, 
  'include'                   => null, 
  'topic_count_text_callback' => default_topic_count_text,
  'link'                      => 'view', 
  'taxonomy'                  => 'post_tag', 
  'echo'                      => true,
  'child_of'                  => null, //覆盖includes
);
wp_tag_cloud( $args );
?> 
  1. WP Tab Widget: 这个插件可以将热门标签转化为一个可滑动的Tab,显示在侧边栏或其他位置。除了标签,还可以添加其他模块,如最新文章、热门文章等。
<?php
//在主题中显示Tab中的标签
if (class_exists('WP_Tab_Widget')) {
    $widget_id = $wpdb->get_var("SELECT id FROM $wpdb->options WHERE option_name='widget_wptw' LIMIT 1");
    $widgets = wp_get_sidebars_widgets();
    if (isset($widgets['sidebar-1']) && is_array($widgets['sidebar-1']) && in_array($widget_id, $widgets['sidebar-1'])) {
        $tabs = get_post_meta($widget_id, 'wptw-opts', true);
        if (is_array($tabs) && count($tabs) > 0) {
            foreach ($tabs as $i => $tab) {
                if ($tab['type'] == 'tags') {
                    $args = array(
                        'smallest'  => 10,
                        'largest'   => 18,
                        'unit'      => 'px',
                        'number'    => $tab['number'],
                        'orderby'   => 'count',
                        'order'     => 'DESC',
                        'format'    => 'flat',
                        'separator' => ', ',
                        'taxonomy'  => $tab['taxonomy'],
                        'echo'      => true,
                        'link'      => 'view',
                    );
                    echo '<div class="tab-pane fade';
                    if ($i == 0) echo ' in active';
                    echo '" id="tab-' . $i . '">';
                    echo '<h4>' . esc_html($tab['title']) . '</h4>';
                    wp_tag_cloud($args);
                    echo '</div>';
                }
            }
        }
    }
}
?> 
  1. Top 10: 这个插件记录网站中最热门的文章、页面、评论和标签,并可以在侧边栏等位置显示。
<?php
//在主题中显示热门标签
if (function_exists('get_tptn_post_count')) {
    $tags = get_tptn_most_used_tags('10', 'post');
    if ($tags) {
        echo '<div class="widget widget-tags-top-posts">';
        echo '<h3 class="widget-title">热门标签</h3>';
        echo '<div class="tagcloud">';
        foreach ($tags as $tag) {
            echo '<a href="' . esc_url(get_tag_link($tag->term_id)) . '" class="tag-link-' . absint($tag->term_id) . '" title="' . esc_attr($tag->name) . '" style="font-size: ' . esc_attr($tag->font_size) . 'px;">' . esc_html($tag->name) . '</a>';
        }
        echo '</div></div>';
    }
}
?> 
大家谈论
    我的见解