Skip to:
Content
Pages
Categories
Search
Top
Bottom

Tag Cloud – set number of tags


  • larrymac
    Participant

    @larrymac

    I’ve set up a BuddyPress page using the Magazine Basic theme. The tag cloud works fine, but I’d like to limit the number of top tags that it displays – it just looks huge and cluttered right now. I did some snooping through the config files looking for a way to set or change it, but couldn’t find anything that looked obvious to an admitted noob.

    Any help would be greatly appreciated. Thx

Viewing 9 replies - 1 through 9 (of 9 total)

  • Henry
    Member

    @henrywright-1

    Do you mean a WordPress tag cloud as in wp_tag_cloud()?

    <?php 
    wp_tag_cloud( array( 'number' => '8' ) ); 
    ?>

    larrymac
    Participant

    @larrymac

    That looks like exactly what I’m looking for. Which file is that in? I couldn’t find anything like that!


    Henry
    Member

    @henrywright-1

    This snippet is what you need to paste into your file:

    <?php 
    wp_tag_cloud( array( 'number' => '8' ) ); 
    ?>

    If you are already using a tag cloud then find it and remove it. A basic tag cloud will look something like this:

    wp_tag_cloud()


    larrymac
    Participant

    @larrymac

    Thanks. Not sure if I know where I should be looking, though. I did find the code below in wp-admin/edit-tags.php. Am I in the right spot? If so, do I delete all of that?

    Thanks for the patience.

    <?php
    
    if ( !is_null( $tax->labels->popular_items ) ) {
    	if ( current_user_can( $tax->cap->edit_terms ) )
    		$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
    	else
    		$tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
    
    	if ( $tag_cloud ) :
    	?>
    <div class="tagcloud">
    <h3><?php echo $tax->labels->popular_items; ?></h3>
    <?php echo $tag_cloud; unset( $tag_cloud ); ?>
    </div>

    larrymac
    Participant

    @larrymac

    For anybody else who runs into this, I found a quick and easy way: you can change the default number of tags returned in wp-includes/category-template.php

    Please never advise people edit core files. Core files must never be edited as you may cause unintended issues to develop and changes will be overwritten on update.

    The code Henry showed is how one displays a tag cloud in template files https://codex.wordpress.org/Function_Reference/wp_tag_cloud

    The question is how your theme is handling this, directly coded to sidebar/s? some function that is called in some manner? hard to tell how the theme manages it so you really need to address the question to the theme author, also it not really a BP question really as this is a WP function.


    larrymac
    Participant

    @larrymac

    Good point on editing the core files, I hadn’t thought of that. I couldn’t find where to make those changes – or to what extent I needed to make them – and came across that while I was looking. But you’re right: everybody ignore my previous advice and do it the right way. 😉

    I’m still shaky on where WP ends and BP begins…lol.

    Examine your themes sidebars, functions.php and plain old widgets to try and fathom where the tagcloud is being set from if it’s custom i.e not just the WP widget and you can find it then you should be able to pass it args as in the link above but equally editing a core theme file will suffer same fate as any ‘core’ file that can be updated so always try and work in child themes.


    danbp
    Participant

    @danbp

    hi @larrymac

    did you find/tested this solution ?

    Limit number of tags in WordPress tag cloud widget

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Tag Cloud – set number of tags’ is closed to new replies.
Skip to toolbar