WordPress.org

Forums

[resolved] [Plugin: NextGEN Gallery] tagcloud behaviour in sidebar, thumbs in main content (18 posts)

  1. zyrq
    Member
    Posted 6 years ago #

    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?

    http://wordpress.org/extend/plugins/nextgen-gallery/

  2. topherhenderson
    Member
    Posted 6 years ago #

    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...

  3. zyrq
    Member
    Posted 6 years ago #

    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):
    http://wordpress.org/support/topic/210246?replies=35
    http://www.soulrinse.com/soulblog/how-to-create-a-nextgen-gallery-tag-cloud/
    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
    http://mysite.com/nggallery/page-87/tags/mytag
    to this shortcode [nggtags album=mytag]

  4. zyrq
    Member
    Posted 6 years ago #

    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

  5. roberthq
    Member
    Posted 6 years ago #

    zyrq-
    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
    http://wordpress.org/support/topic/210246?replies=35

    http://www.soulrinse.com/soulblog/how-to-create-a-nextgen-gallery-tag-cloud/

    But can't make them work.
    RRG

  6. zyrq
    Member
    Posted 6 years ago #

    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 http://example.com/tags (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">
    <?php
    // based on http://www.soulrinse.com/soulblog/how-to-create-a-nextgen-gallery-tag-cloud/
    //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=http://example.com/nggallery/page-87/tags/";
    echo $row->slug;
    echo ">";
    echo $row->name;
    echo "</a> </li> ";
    }
    ?>
    </ul>

    FWIW

  7. roberthq
    Member
    Posted 5 years ago #

    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: http://www.hqprints.net/archives/category/landscapearchitecture

    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">
    <?php
    // based on http://www.soulrinse.com/soulblog/how-to-create-a-nextgen-gallery-tag-cloud/
    //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 "

  8. <a href="http://www.hqprints.net/tags";
    echo $row->slug;
    echo ">";
    echo $row->name;
    echo "
  9. ";
    }
    ?>

    does nothing. I'm not sure why...any ideas?

  10. zyrq
    Member
    Posted 5 years ago #

    Looong time ago, from memory: try changing this
    <a href="http://www.hqprints.net/tags";
    to this
    <a href="http://www.hqprints.net/nggallery/page-put_your_pageid_here/tags/";
    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

  11. rughooking
    Member
    Posted 5 years ago #

    Has anyone gotten this to work on 2.9?

  12. MaryE
    Member
    Posted 5 years ago #

    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.

    M.

  13. psperkins
    Member
    Posted 5 years ago #

    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 = 'http://your.homedomainhere.com';

    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.

  14. psperkins
    Member
    Posted 5 years ago #

    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.

  15. psperkins
    Member
    Posted 5 years ago #

    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); ?>
        </div>
  16. psperkins
    Member
    Posted 5 years ago #

    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 ) )
    		return;
    
    	foreach ( $tags as $key => $tag ) {
    		if ( 'edit' == $args['link'] )
    			$link = get_edit_tag_link( $tag->term_id, $args['taxonomy'] );
    		else
    			$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 ) )
    		return;
    
    	$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
    	if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin
    		$tags = $tags_sorted;
    		unset($tags_sorted);
    	} else {
    		if ( 'RAND' == $order ) {
    			shuffle($tags);
    		} 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);') );
    			else
    				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 = 'http://your.domain.here.com';
    		$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;
    		break;
    	case 'list' :
    		$return = "<ul class='wp-tag-cloud'>\n\t<li>";
    		$return .= join( "</li>\n\t<li>", $a );
    		$return .= "</li>\n</ul>\n";
    		break;
    	default :
    		$return = join( $separator, $a );
    		break;
    	endswitch;
    
        if ( $filter )
    		return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
        else
    		return $return;
    }
  17. slayaz
    Member
    Posted 5 years ago #

    wow!

    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

  18. slayaz
    Member
    Posted 5 years ago #

    s'ok sorted it!

    i have one final question.

    is anyone still here?

  19. psperkins
    Member
    Posted 5 years ago #

    Yeah - still here. I subscribed to this topic so I check it semi frequently.

  20. psperkins
    Member
    Posted 5 years ago #

    I use the page-link-manager plugin to manage excluding pages from wp navigation list, it works great.

    http://wordpress.org/extend/plugins/page-link-manager/

    Don't forget to change this line in the function (above) - links won't work correctly without it. There are other things to consider - like your permalink structure, etc. I almost always try to use %category%/%postname% for permalink structure as it seems to be the most malleable. This particular solution will have to be customized to fit your permalink structure if using something different.

    The link for each tag is assembled in this "foreach" statement within the function:

    foreach ( $tags as $key => $tag ) {
    		$count = $counts[ $key ];
    		$real_count = $real_counts[ $key ];
    		$tag_link = 'http://your.domain.here.com';
    		$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>";
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic