Before you ask please READ THIS

Tag Widget limits

in Fame Posts: 119
Hi there,
how are you? I have this new questions... :-)
Is it possible to set a limit to the tags that the tags widget show on the sidebar?
I've set a widget called Brands (as in your site) but as I will have many brands they are too much. Is that possible and is it possible to set them on random?
Regards
Gab
screenshot_air.jpg
1366 x 768 - 154K

Comments

  • AirAir
    Posts: 10,970
    Hello:-)

    This should help you http://mekshq.com/limit-number-of-tags-in-wordpress-tag-cloud-widget/

    With kind regards.
  • Posts: 119
    HI.. that's code is not working... But it doesn't matter.. I deleted the widget... :-)
    Thanks
  • AirAir
    Posts: 10,970
    Indeed, this code work for classic Tags. For product tags use this code
    
    //Register tag cloud filter callback
    add_filter('woocommerce_product_tag_cloud_widget_args', 'tag_widget_limit');
    
    //Limit number of tags inside widget
    function tag_widget_limit($args){
    
        //Check if taxonomy option inside widget is set to tags
        if(isset($args['taxonomy']) && $args['taxonomy'] == 'product_tag'){
            $args['number'] = 2; //Limit number of tags
        }
    
        return $args;
    }
    With kind regards.
  • Posts: 119
    Hi... thanks ... I will check this later... i do have another problem and I'm opening a new post..
    :-)
  • Posts: 119
    Hi my friend,
    can I ask you if is it possible to tell to this code to display the tags in random mode? It's displaying me always the same tags..
    Thanks million...
  • AirAir
    Posts: 10,970
    Hello:-)

    I thought it would be easy, but it is not. Rather you will need some different, or modified widget for this. Sorry.

    With kind regards.
  • Posts: 119
    No problem my friend... I will look around... thanks
  • edited August 2015 Posts: 119
    Hi my friend...
    How are you? Listen I've talking with Woothemes about the fuction WC Products Tags and they gave me this function to have them in random way..

    add_filter( 'woocommerce_product_tag_cloud_widget_args', 'custom_woocommerce_product_tag_cloud_widget_args' );
    function custom_woocommerce_product_tag_cloud_widget_args( $args ) {

    $args['order'] = 'RAND';
    $args['number'] = '10';

    return $args;

    }
    The problem with this function is that the 10 tags displaied are all the same all the time and I have something like 50 tags to be displaied in random way.
    They told me that is not their business to change codes.
    So my question is: are you able to change this code in the way that the fuction will look at all the tags and show only 15 of them in the pages?
    Obviously I will pay you for this service if you can tell me that you can do that.
    Let me know.
    Regards
    Gabriele
    Post edited by Air on
  • AirAir
    edited August 2015 Posts: 10,970
    Hello there

    I have checked, and wordpress forces tags to display in order of how many times there were used.
    To change it, you will have to either create special widget for this or modify wordpress source code.

    Mainly file wordpress\wp-includes\category-template.php line ~621 , change
    $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
    to
    $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'rand', 'order' => 'DESC' ) ) ); // Always query top tags
    Writing own widget, that will not use standard wordpress code for tag cloud, should be proper solution, but I won't do this for you, sorry.

    However with all that information, someone should easily do that for you if he/she knows WP :-)

    With kind regards.
    Post edited by Air on
  • Posts: 119
    Hi .. thanks for your answer...
    I saw that line and I changed it to RAND, but I dind't know it would have displayed the most viewed.
    I also upload last week another plugin and guess ... it broken many website links and I had to installed again all the website...
    I was lucky I had the products bakcup..
    Anyway... thanks


  • AirAir
    Posts: 10,970
    garocchi said: I saw that line and I changed it to RAND,
    Did it work for you?
    garocchi said: I also upload last week another plugin and guess ... it broken many website links and I had to installed again all the website...
    What plugin?

    With kind regards.
  • Posts: 119
    No, it didn't work... it took always the same 10 tags and displayed always the same, but in random order...
    The plugin was Ultimate Tag Cloud..
    It has broken some links in woocommerce and categories and bla bla bla
  • AirAir
    Posts: 10,970
    But do you use Woocommerce widget for your tags, or this "Ultimate Tag cloud" one?
    I am sure this change works, as I tested it before posting. I tested it on Woocommerce product tags widget.

    With kind regards.
  • Posts: 119
    I used the wc product tags, but as it cannot do what I was looking for I tried the "Ultimate tag cloud" and I ruined everything... :-):-):-)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!