WordPress.org

Forums

How To Show Select Tags in Tag Cloud (17 posts)

  1. Mahesh Mohan
    Member
    Posted 2 years ago #

    Hi,

    Can you please tell me how to show only SELECT Tags in Tag cloud in Sidebar Widget.

    I want to show only the primary tags in sidebar and want to hide all others. So that it appear on each blogposts only and wont crowd in sidebar.

    If you check http://www.minterest.com/ then it shows all the tags in sidebar and its crowded.. so I thought it would be nice if I show only select tags as others will be visible when you go to a single post.

    Thanks!

  2. Mahesh Mohan
    Member
    Posted 2 years ago #

    Tell me how to do that without using any plugins..

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    http://www.transformationpowertools.com/wordpress/edit-widget-parameters-filter-wordpress
    http://codex.wordpress.org/Function_Reference/wp_get_post_tags

    add this to functions.php of your theme:

    add_filter('widget_tag_cloud_args','single_post_tag_cloud_tags');
    function single_post_tag_cloud_tags($args) {
    if( is_single() ) {
    global $post;
    $post_tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
    $args = array('include' => implode(',',$post_tag_ids));
    }
    return $args; }
  4. Mahesh Mohan
    Member
    Posted 2 years ago #

    Hey, I want to add the Tag Cloud to Sidebar by showing only SELECT Tags and not all.

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    Hey, I want to add the Tag Cloud to Sidebar... choosing the ID of tags.

    ?

    - are you using the default tag cloud widget?
    - do you want to show only the tags of the current post in the sidebar?

    if yes to both, then the suggested code should work for you.

    if you want to select the tags in a different way, please post more details.

    or consider using a plugin - http://wordpress.org/extend/plugins/search.php?q=tag+cloud+widget&sort=

  6. Mahesh Mohan
    Member
    Posted 2 years ago #

    Hi..

    Please check out http://www.minterest.com/ you can see my Tag Cloud there in sidebar (2nd last widget)...

    But its showing all the tags I have added to my blog.. Now what I want is show only select tags there.... so that widget appears on all Pages...

    Got it?

  7. alchymyth
    Forum Moderator
    Posted 2 years ago #

    one possibility:
    for a fixed sub-set of tags, try to add this to functions.php of your theme:
    (you will need to use the tag IDs to build the list)

    add_filter('widget_tag_cloud_args','selected_tags_tag_cloud);
    function selected_tags_tag_cloud($args) {
    $args = array('include' => '3,7,45,75,123');
    return $args; }
  8. Mahesh Mohan
    Member
    Posted 2 years ago #

    Okay. Where should I paste this code?

    My functions.php file code is

    [Code moderated as per the Forum Rules. Please use the pastebin]

  9. Mahesh Mohan
    Member
    Posted 2 years ago #

    Hi,

    I got the idea.. Can you please tell me how to modify this... to select the tags required..

    <?php wp_tag_cloud(''); ?>

    How to add filters to this?

  10. alchymyth
    Forum Moderator
    Posted 2 years ago #

    Where should I paste this code?

    anywhere after the first <?php and before the last ?> without breaking any existing functions.

    http://codex.wordpress.org/Functions_File_Explained

  11. Mahesh Mohan
    Member
    Posted 2 years ago #

    No. Please check the previous question... I got another alternative..

    My Theme shows tag cloud by default for empty lower sidebar widget.. so I can modify the Sidebar Template

    Where I see the code

    <?php wp_tag_cloud(''); ?>

    So tell me how to filter this.... :)

  12. Mahesh Mohan
    Member
    Posted 2 years ago #

    Am checking http://codex.wordpress.org/Function_Reference/wp_tag_cloud now about how to filter...

  13. Mahesh Mohan
    Member
    Posted 2 years ago #

    Thank you so much... I got it....

    I replaced that code with <?php wp_tag_cloud('include=10,27'); ?>

    So its showing only 2 tags now... Now need to find the IDs of all the tags required...

    Thanks once again! :)

  14. Mahesh Mohan
    Member
    Posted 2 years ago #

    Okay. By the way how to add multiple parameters? I want to display all the tags in same size irrespective of the number of posts filed under that tag.

    In that case what should I do to:

    <?php wp_tag_cloud('include=10,27'); ?>

  15. alchymyth
    Forum Moderator
    Posted 2 years ago #

    try:
    (adjust the font size)

    <?php wp_tag_cloud('include=10,27&smallest=12&largest=12'); ?>

    about how to filter...

    you only need to filter, if you are using the tag cloud widget
    - in your case you seem to be working with the wp_tag_cloud() code directly in sidebar.php (?) and you need to add the right parameters/arguments to the function.

  16. Mahesh Mohan
    Member
    Posted 2 years ago #

    Oh yeah...

    Its working....

    <?php wp_tag_cloud('include=10,27&smallest=12&largest=12'); ?>

    Now how to add more spaces between tags so that one can read more easily?

    Check out the tag cloud now... http://www.minterest.com/sitemap/ (the last sidebar widget)

    What's the best way to separate tags? Now it looks like a single sentence rather than tags.

    Whats the use of parameter "Separator"?

  17. Mahesh Mohan
    Member
    Posted 2 years ago #

    Never mind... I think I will go for default syle itself.. as it looks good... i will remove more themes so it will be better...

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic