2017-08-19 3 views
1

このコード(http://devotepress.com/faqs/display-popular-tags-wordpress)を見つけましたが、ショートコード([wpb_popular_tags])を使用しましたが、結果は表示されません。WooCommerceのサイドバーウィジェットで最も人気のある商品タグを表示

最も一般的なWooCommerce製品タグを表示するためにこのコードを使用するにはどうすればよいですか?ここで

は自分のコードです:あなたが知らないことを知っている必要が何をすべきか

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'); 
+0

これを試してください:http://www.wpbeginner.com/plugins/how-to-display-most-popular-tags-in-wordpress/ –

答えて

0

まず、ことがあります
クラシックWordPressのポストタグ持ってWooCommerce「商品タグ」よりも非常に異なっています異なるカスタム分類学'product_tag'

したがって、WordPress get_tags()を使用して商品タグを取得することはできません。どのプラグインでも

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ファイルに行くか:

代わりに、get_terms('product_tag')でこのようにそれを置き換える必要がありますファイル。

USAGE - あなたがする必要があります。あなたのwoocommerceウィジェットバーエリアで "テキスト" ウィジェットを追加

  1. あなたはすべてのあなたの「最も人気のある」製品タグ *(ものを取得します。この「テキスト」のショートコード[wpb_popular_tags]ウィジェット(そして保存)

のエディタでこの時間を追加します。あなたの製品に設定して有効にしたもの)* s。

WooCommerce 3+でテストされ、完全に動作します。

+1

ありがとう – arz

関連する問題