在WooCommerce侧边栏小部件区域中显示最受欢迎的产品标签 [英] Display Most Popular Product Tags in WooCommerce sidebar widgets area

查看:297
本文介绍了在WooCommerce侧边栏小部件区域中显示最受欢迎的产品标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了此代码( http://devotepress.com/faqs/display- Popular-tags-wordpress ),我使用了短代码([wpb_popular_tags]),但看不到任何结果。

I found this code (http://devotepress.com/faqs/display-popular-tags-wordpress) and I used the short code ([wpb_popular_tags]) but I do not see any result.

如何使用此代码

这是他们的代码:

function wpb_tag_cloud() {
    $tags = get_tags();
    $args = array(
        'smallest' => 10,
        'largest' => 22,
        'unit' => 'px',
        'number' => 10,
        'format' => 'flat',
        'separator' => " ",
        'orderby' => 'count',
        'order' => 'DESC',
        'show_count' => 1,
        'echo' => false
    );

    $tag_string = wp_generate_tag_cloud( $tags, $args );

    return $tag_string;
}

// Add a shortcode so that we can use it in widgets, posts, and pages
add_shortcode('wpb_popular_tags', 'wpb_tag_cloud');

// Enable shortcode execution in text widget
add_filter ('widget_text', 'do_shortcode'); 


推荐答案

首先,您必须知道自己不知道什么不知道可能是:

经典WordPress帖子标签与WooCommerce的产品标签非常不同。其中具有不同的自定义分类法'product_tag'

First, what do you have to know that you don't know may be:
Classic WordPress post tags are very different than WooCommerce "Product tags" which have a different custom taxonomy 'product_tag'.

所以您不能使用WordPress get_tags( )来获取产品标签。

So you cant use WordPress get_tags() to get the product tags.


相反,您应该将其替换为 get_terms('product_tag') 这样:

Instead you should replace it with get_terms( 'product_tag' ) this way:


function wpb_tag_cloud() {
    $tags = get_terms( 'product_tag' );
    $args = array(
        'smallest' => 10,
        'largest' => 22,
        'unit' => 'px',
        'number' => 10,
        'format' => 'flat',
        'separator' => " ",
        'orderby' => 'count',
        'order' => 'DESC',
        'show_count' => 1,
        'echo' => false
    );
    $tag_string = wp_generate_tag_cloud( $tags, $args );
    return $tag_string;
}

// Add a shortcode so that we can use it in widgets, posts, and pages
add_shortcode('wpb_popular_tags', 'wpb_tag_cloud');

// Enable shortcode execution in text widget
add_filter ('widget_text', 'do_shortcode'); 

代码会出现在您活动的子主题(或主题)的function.php文件中或任何插件文件中。


使用情况-您需要:


  1. 添加文本

  2. 在此文本编辑器中添加小部件 [wpb_popular_tags] (然后保存)

  1. Add the "text" widget in your woocommerce widget bar area.
  2. Add in the editor of this "text" widget the short code [wpb_popular_tags] (then save)

这次,您将获得所有最受欢迎产品标签 *(您为产品设置并启用的产品标签)* s。

This time you will get All your "most popular" product tags *(The ones that you have set and enabled for your product)*s.

在WooCommerce 3+中经过测试,可以正常使用

Tested in WooCommerce 3+ and perfectly works.

这篇关于在WooCommerce侧边栏小部件区域中显示最受欢迎的产品标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆