Support » Plugins » [Plugin: NextGEN Gallery] tagcloud behaviour in sidebar, thumbs in main content

  • Resolved zyrq


    I have a Page called MyPics which holds an album:
    [album id=3 template=extend]

    I would like a image [tagcloud] in the sidebar to behave like the ‘normal’ WP tags where the tagged post(s) get displayed in the main content area. So if you click a tag in the image tagcloud the thumbs get displayed in the main content area.

    Currently image tags get replaced with the thumbs, so you always need to go back to see the tagcloud again.

    Any thoughts how to handle this?

Viewing 15 replies - 1 through 15 (of 17 total)
  • I’m having the same issue!

    Even a ‘back’ button which brings back the tagcloud would be useful, so that I can at least use the tagcloud on its own page…

    This thread has an example of how to list the tags in the sidebar, but based on an earlier version of NGG (other tables, before its built-in Tagcloud):
    Still not sure how to get the images to display in the main part of the page…
    must be a matter of translating this url
    to this shortcode [nggtags album=mytag]

    thats it! just this shortcode: [nggtags album=tag]
    list the tags in the sidebar through a custom query with the new tables
    enter the shortcode on the main page



    From what I understand that your saying…Nextgen gallery now has a built in text cloud feature in the newer version?? I’ve been searching for this and can’t make it work. Any insight would be great! As well, i’ve added the short code to a post [nggtags album=tag] and it does nothing. I’m thinking something is not right or an option is not checked someplace. I’ve been over and over this…

    Any ideas?
    Thanks zyrq
    p.s.I’ve also gone to the two links

    But can’t make them work.

    Let’s see if I can help with what I remember how I tested this…
    Tags get listed in the sidebar through a custom query; pics are shown in main part of the page with a permalink of (pageid=87). Shortcode on that page is simply [nggtags album=tag].
    Below is the “code” for the sidebar

    <h3>test tagcloud sidebar</h3>
    <ul class="galtags">
    // based on
    //qry to get the tags:
    global $wpdb;
    //custom list with data from NGG tables
    $results = $wpdb->get_results('SELECT * FROM wp_terms INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_taxonomy_id WHERE taxonomy = "ngg_tag"');
    foreach ($results as $row) {
    //I figured out the url of page containing the [nggtags album=tag] shortcode (my pageid=87)
    echo "<li><a href=";
    echo $row->slug;
    echo ">";
    echo $row->name;
    echo "</a> </li> ";




    Hey zyrq
    Thanks for getting back. I sort of forgot about wanting to get this done as I’m busy as hell during the summer.

    I created a temp and crap work around for now, you can see it for example here:

    The goal was to have a php widget with the tags as I don’t have a side bar and it would be on the footer on the right. I attempted this again with your code and a no go.

    This is the code I changed after adding a page and a post with the short code (I tried both)

    <ul class=”galtags”>
    // based on
    //qry to get the tags:
    global $wpdb;
    //custom list with data from NGG tables
    $results = $wpdb->get_results(‘SELECT * FROM wp_terms INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_taxonomy_id WHERE taxonomy = “ngg_tag”‘);
    foreach ($results as $row) {
    //I figured out the url of page containing the [nggtags album=tag] shortcode (my pageid=87)
    echo ”

  • <a href=””;
    echo $row->slug;
    echo “>”;
    echo $row->name;
    echo ”
  • “;

    does nothing. I’m not sure why…any ideas?

    Looong time ago, from memory: try changing this
    <a href=””;
    to this
    <a href=””;
    figure out the url of the page containing the [nggtags album=tag] shortcode
    for me the pageid was 87, check yours
    and see if that works

    Has anyone gotten this to work on 2.9?

    I was taking the approach of just changing the plugin code and worrying about the change (delta) in the “next” release. It looks like you discovered the album tags, and they work with my 2.9 test install. I’ll throw in what I’ve discovered …

    The file “nggfunctions.php” contains the shortcode functions (I think you already discovered this). It should be straight forward to force the tag cloud to always show — look at lines 1017 – 1023, that’s where the arguments of the url are queried. Note that on line 1023 there’s a return. You probably would want to move this conditional that to the bottom of the function (remove the return) and you’d have the result desired on the original request.

    The sidebar is a little trickier, at this point, it may be worth just breaking up the functions and calling directly from the theme. A more elegant solution would be adding an argument to the shortcode (something like show=”album, cloud replace or both” with the default of replace.

    The other issue of changing the target of the tag itself to point to another page can also be accomplished with a code. The easiest thing here is to have a default page as suggested above, modify the code (line 1015 of nggfunctions.php) to use it, and to place the ‘[tagcloud]` tag in the body of this page. This simple change could not coexist with having tags embedded in other pages or posts, unless an argument is added to the tagcloud shortcode, or the function is cloned and called directly (or another shortcode set up …)

    One thing that cannot be done without a deeper code change (I think) is to place the tagcloud in a WordPress archive or search page. The permalink code assumes a page or a post. The permalink method is in the file rewrite.php in the ‘lib’ folder.


    I came across this very issue today and I struggled for hours trying to get this to work in wp 2.9.1

    What I found out, is that ngGallery is using the wordpress function wp_tag_cloud and it’s dependent wp_generate_tag_cloud to build the list with links included.

    What I did was copy the two functions out of wp-includes/category-template.php into my own theme’s functions.php file.

    Then I changed the names of them from “wp_tag_cloud” to “ng_tag_cloud” – same for the other function. *Don’t forget that wp_tag_cloud calls for wp_generate_tag_cloud around line 26 – change that too.

    Then, towards the bottom of the function ng_generate_tag_cloud (or whatever you renamed it in your functions.php file) – right above the switch at the bottom – you will see where it is building the link.

    Change the line that says $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';'
    to something more like: $tag_link = '';

    and then change the line $a[] = "<a href='$tag_link'...
    to something more like: $a[] = "<a href='$tag_link$tag_name?gallerytag=$tag_name'...

    Then in my sidebar.php I call `<?php ng_tag_cloud(); ?> to call the function. You can use an array of args just like the default wp_tag_cloud function and set up your list however you’d like.

    Working great now, and affords some decent level of customization.

    Oh – let’s not forget that every tag has to have a corresponding page with the [nggtags album=your-tag-here] tag that matches your content call.

    The code from my sidebar.php

    <div class="widget tags">
        	<h2>Photo Tags</h2>
    	<?php $args = array(
    	    'smallest'  => 9,
    	    'largest'   => 9,
    	    'unit'      => 'pt',
    	    'number'    => 45,
    	    'format'    => 'flat',
    	    'separator' => '<br />',
    	    'orderby'   => 'name',
    	    'order'     => 'ASC',
    	    'exclude'   => '',
    	    'include'   => '',
    	    'link'      => 'view',
    	    'taxonomy'  => 'ngg_tag',
    	    'echo'      => true ); ?>
    <?php echo ng_tag_cloud($args); ?>

    in my functions.php

    function ng_tag_cloud( $args = '' ) {
    	$defaults = array(
    		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
    		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
    		'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
    	$args = wp_parse_args( $args, $defaults );
    	$tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
    	if ( empty( $tags ) )
    	foreach ( $tags as $key => $tag ) {
    		if ( 'edit' == $args['link'] )
    			$link = get_edit_tag_link( $tag->term_id, $args['taxonomy'] );
    			$link = get_term_link( intval($tag->term_id), $args['taxonomy'] );
    		if ( is_wp_error( $link ) )
    			return false;
    		$tags[ $key ]->link = $link;
    		$tags[ $key ]->id = $tag->term_id;
    	$return = ng_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
    	$return = apply_filters( 'wp_tag_cloud', $return, $args );
    	if ( 'array' == $args['format'] || empty($args['echo']) )
    		return $return;
    	echo $return;
    function ng_generate_tag_cloud( $tags, $args = '' ) {
    	global $wp_rewrite;
    	$defaults = array(
    		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
    		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
    		'topic_count_text_callback' => 'default_topic_count_text',
    		'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
    	if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
    		$body = 'return sprintf (
    			_n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
    			number_format_i18n( $count ));';
    		$args['topic_count_text_callback'] = create_function('$count', $body);
    	$args = wp_parse_args( $args, $defaults );
    	extract( $args );
    	if ( empty( $tags ) )
    	$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
    	if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin
    		$tags = $tags_sorted;
    	} else {
    		if ( 'RAND' == $order ) {
    		} else {
    			// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
    			if ( 'name' == $orderby )
    				uasort( $tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') );
    				uasort( $tags, create_function('$a, $b', 'return ($a->count > $b->count);') );
    			if ( 'DESC' == $order )
    				$tags = array_reverse( $tags, true );
    	if ( $number > 0 )
    		$tags = array_slice($tags, 0, $number);
    	$counts = array();
    	$real_counts = array(); // For the alt tag
    	foreach ( (array) $tags as $key => $tag ) {
    		$real_counts[ $key ] = $tag->count;
    		$counts[ $key ] = $topic_count_scale_callback($tag->count);
    	$min_count = min( $counts );
    	$spread = max( $counts ) - $min_count;
    	if ( $spread <= 0 )
    		$spread = 1;
    	$font_spread = $largest - $smallest;
    	if ( $font_spread < 0 )
    		$font_spread = 1;
    	$font_step = $font_spread / $spread;
    	$a = array();
    	foreach ( $tags as $key => $tag ) {
    		$count = $counts[ $key ];
    		$real_count = $real_counts[ $key ];
    		$tag_link = '';
    		$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
    		$tag_name = $tags[ $key ]->name;
    		$a[] = "<a href='$tag_link$tag_name?gallerytag=$tag_name' class='tag-link-$tag_id' title='" . esc_attr( $topic_count_text_callback( $real_count ) ) . "' style='font-size: " .
    			( $smallest + ( ( $count - $min_count ) * $font_step ) )
    			. "$unit;'>$tag_name</a>";
    	switch ( $format ) :
    	case 'array' :
    		$return =& $a;
    	case 'list' :
    		$return = "<ul class='wp-tag-cloud'>\n\t<li>";
    		$return .= join( "</li>\n\t<li>", $a );
    		$return .= "</li>\n</ul>\n";
    	default :
    		$return = join( $separator, $a );
        if ( $filter )
    		return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
    		return $return;


    Thanks psperkins, that (sort of) works excellently!

    Although I am sure that is down to my lack of skills than your code.

    I see above you say you need a page for each tag, which i have but the pages appear in the navigation, is there a way to stop them showing in the main nav?

    Thanks again

    s’ok sorted it!

    i have one final question.

    is anyone still here?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Plugin: NextGEN Gallery] tagcloud behaviour in sidebar, thumbs in main content’ is closed to new replies.