• Hi,

    If anyone knows of a way to insert the [tagcloud] shortcode in a sidebar widget, please share the wisdom.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Yeah, that would be nice!!

    Thread Starter Gene53

    (@gene53)

    Yeah, that would be nice!!

    IMO, a sidebar widget would be a plus and a heck of a lot better than on a page.

    It really would.

    Got the tag cloud in the sidebar by adding add_filter('widget_text', 'do_shortcode'); to functions.php. The problem is that the results also show in the sidebar. Need to learn more to figure this out.

    Rughooking,

    I got it to work with some code changes, provided both the tagcloud and its gallery are on the same page. Not sure that is what you are looking for. If you are, happy to share.

    It involves a change to the nggfunctions.php file and a one line modification to the short codes (the version I had did not pass on the attributes from the shortcode).

    With these changes, I can control the output of the shortcode:

    [tagcloud show=cloud] shows the tagcloud only
    [tagcloud show=gallery] shows the gallery only

    I changed the default to show both. Not fully tested.

    Also added a title into the gallery to indicate which tag is being shown. So if the target page/post is the same for both the tag cloud and gallery, it’s ok. I’m having a few more challenges with targeting the output to another page from an attribute. Different file, different set of parameters …

    M.

    I’m very interested in how you did this MaryE.
    Can you tell me?

    Thread Starter Gene53

    (@gene53)

    @marye Wow! Once you have all the code and the bugs ironed out, will you be making this into a plugin?

    @marye

    Isecond Fokkio and Gene53.

    Can you share your edits to nggfunctions.php?

    Seems as MaryE won’t be back to help out.

    A couple of months ago a I tried to solve this with the help from others writing in this forum. This is what I came up with.

    I created a sidebar widget with PHP code inserted.

    First, make sure that you install the plugin Exec-PHP. There are other plugins that also enable PHP execution within posts and pages but I only tested it with Exec-PHP.

    Next, create a page with the name and slug “picturetags” and put [tagcloud] into it.

    Finally, paste the following code into a newly created text widget:

    <ul>
    <?php
    $tags = (array) nggTags::find_tags($param, true);
    foreach( $tags as $tag )
    	{
    	echo "<a href=../wp-content/nggallery/picturetags/?gallerytag=";
    	echo $tag->slug;
    	echo ">";
    	echo "<li>";
    	echo $tag->name;
    	echo "</a>";
    	echo '?('.$tag->count.')</li>'."\n";
    	}
    unset($tags);
    ?>
    </ul>

    You will probably have to change this part according to your specific site setup:
    “<a href=../wp-content/nggallery/picturetags/?gallerytag=”;

    To avoid the page “picturetags” showing up at the front page I use the plugin PageMash wich can be used to hide certain pages.

    To make the page “picturetags” somewhat more appealing I also pasted the following into it (before the [tagcloud] code)

    <?php
    $gallerytag = (get_query_var('gallerytag')); 		// get the slug
    			$gallerytag = str_replace("-", " ", $gallerytag); 	// replace dashes with spaces
    			$gallerytag = ucwords($gallerytag);					// capitalize words
                            echo 'The pictures below are displayed since you clicked the picture tag "'.$gallerytag.'". Click the image.';
    			echo '<h3>'.$gallerytag.'</h3>'; 					// show the result
    ?>
    
    <?php $tags = wp_get_object_terms($image->pid,'ngg_tag') ?>
    
    <?php foreach ( $tags as $tag ) : ?>
       <a href="<?php bloginfo('url'); ?>/picturetags/<?php echo $tag->slug; ?>"><?php echo $tag->name; ?></a>
    <?php endforeach; ?>

    What I still didn’t manage to fix is a tagcloud with font sizes corresponding to number times a particular tag is used. Any help with this is appreciated!

    It’s been a while since I looked at this, and since then I’ve lost most of the changes. However, if you look at nggfunctions.php, you will see the tagcloud function — nggTagCloud().

    This function has two returns in it — the first returns the gallery if a tag is specified in the querystring. If there is no tag in the querystring, then the second return produces the tagclould itself. So, instead of the returns, you can save these strings into an output and control how they are returned based upon the value in the tag.

    I’d have to recreate the actual behavior I did last year, but as a start you can try the following to always produce the tagcloud regardless of the query sting (see comments for the changes):

    function nggTagCloud($args ='', $template = '') {
        global $nggRewrite;
    
        // $_GET from wp_query
        $tag     = get_query_var('gallerytag');
        $pageid  = get_query_var('pageid');
    /** new output variable to store gallery **/
        $out1 = "";
    
        // look for gallerytag variable
        if ( $pageid == get_the_ID() || !is_home() )  {
            if (!empty( $tag ))  {
    
                $slug =  esc_attr( $tag );
    
    /** change to a variable **/
                $out1  =  nggShowGalleryTags( $slug );
    /** delete the return **/
                /** return $out; **/
            }
        }
    
        $defaults = array(
            'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
            'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
            'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'ngg_tag'
        );
        $args = wp_parse_args( $args, $defaults );
    
        $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
    
        foreach ($tags as $key => $tag ) {
    
            $tags[ $key ]->link = $nggRewrite->get_permalink(array ('gallerytag' => $tag->slug));
            $tags[ $key ]->id = $tag->term_id;
        }
    
        $out = '<div class="ngg-tagcloud">' . wp_generate_tag_cloud( $tags, $args ) . '</div>';
    
    /** change to generate both tagcloud and gallery (if gallery exists **/
        return $out . $out1;
    }

    I think it would be better to copy this into some other file instead of changing base code, so this was intended as a start. If I get around to looking at this again this vacation, I’ll repost – the last piece is looking into parsing the shortcode and controlling the output of tagcloud and gallery ($out1 and $out).

    What I’d really like to do is produce a widget that can generate a separate page based on a tag page template, but that’s a lot more work.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: NextGEN Gallery] Can the tagcloud be in a sidebar widget?’ is closed to new replies.