{"id":891,"date":"2012-12-09T16:13:07","date_gmt":"2012-12-09T05:13:07","guid":{"rendered":"http:\/\/howden.net.au\/thowden\/?p=891"},"modified":"2012-12-09T16:13:07","modified_gmt":"2012-12-09T05:13:07","slug":"nextgen-gallery-wordpress-nggtags-template-caption-option","status":"publish","type":"post","link":"https:\/\/howden.net.au\/thowden\/2012\/12\/nextgen-gallery-wordpress-nggtags-template-caption-option\/","title":{"rendered":"Nextgen Gallery WordPress nggtags template caption option"},"content":{"rendered":"<p>I have a slightly older version of NGG because I have modded it and have yet to transfer those mods to the latest version. But I just made another minor change that I wanted to document before I forget what I did.<\/p>\n<p>Using the [nggtags gallery=tag_selection]\u00a0 works well for showing the images from the gallery that are tagged as an automated gallery creation.<\/p>\n<p>But I wanted to get the captions displayed as well like the syntax for the standard gallery by id display [nggallery id=60 template=caption].\u00a0 So I needed to add the &#8221; template=caption&#8221; as an option for the nggtags shortcode.<\/p>\n<p>Edit \/wp-content\/plugins\/nextgen-gallery\/nggfunctions.php<\/p>\n<p>Around line 867 should start the function into which I inserted the $template value (with relevant comma&#8217;s etc.) at 3 places as highlighted with the new text.<\/p>\n<p>[php highlight=&#8221;1,13,23&#8243;]<br \/>\nfunction nggShowGalleryTags($taglist, $template = &#8221;) {<\/p>\n<p>\/\/ $_GET from wp_query<br \/>\n$pid\u00a0\u00a0\u00a0 = get_query_var(&#8216;pid&#8217;);<br \/>\n$pageid = get_query_var(&#8216;pageid&#8217;);<\/p>\n<p>\/\/ get now the related images<br \/>\n$picturelist = nggTags::find_images_for_tags($taglist , &#8216;ASC&#8217;);<\/p>\n<p>\/\/ look for ImageBrowser if we have a $_GET(&#8216;pid&#8217;)<br \/>\nif ( $pageid == get_the_ID() || !is_home() )<br \/>\nif (!empty( $pid ))\u00a0 {<br \/>\n$out = nggCreateImageBrowser( $picturelist, $template);<br \/>\nreturn $out;<br \/>\n}<\/p>\n<p>\/\/ go on if not empty<br \/>\nif ( empty($picturelist) )<br \/>\nreturn;<\/p>\n<p>\/\/ show gallery<br \/>\nif ( is_array($picturelist) )<br \/>\n$out = nggCreateGallery($picturelist, false, $template);<\/p>\n<p>$out = apply_filters(&#8216;ngg_show_gallery_tags_content&#8217;, $out, $taglist);<br \/>\nreturn $out;<br \/>\n}<\/p>\n<p>[\/php]<\/p>\n<p>That sorts out the function that is called from the\u00a0 \/wp-content\/plugins\/nextgen-gallery\/lib\/shortcodes.php<\/p>\n<p>Around line 114 there is a string evaluation test process that we change to look for a second option referenced as template= etc..\u00a0 shown in the highlighted line.<\/p>\n<p>[php highlight=&#8221;6&#8243;]<\/p>\n<p>if ( stristr( $content, &#8216;[tags&#8217; )) {<br \/>\n$search = &quot;@(?:&lt;p&gt;)*s*[tagss*=s*(.*?)s*]s*(?:&lt;\/p&gt;)*@i&quot;;<br \/>\nif (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {<\/p>\n<p>foreach ($matches as $match) {<br \/>\n$replace = &quot;[nggtags gallery=&quot;{$match[1]}&quot; template=&quot;{$match[2]}&quot;]&quot;;<br \/>\n$content = str_replace ($match[0], $replace, $content);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>[\/php]<\/p>\n<p>Finally around line 273 there is the call to the nggShowGalleryTags in the show_tags function. Insert a new line for $template as a parameter and to the output option.<\/p>\n<p>[php highlight=&#8221;5,12&#8243;]<\/p>\n<p>function show_tags( $atts ) {<\/p>\n<p>extract(shortcode_atts(array(<br \/>\n&#8216;gallery&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; &#8221;,<br \/>\n&#8216;template&#8217;\u00a0 =&gt; &#8221;,<br \/>\n&#8216;album&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; &#8221;<br \/>\n), $atts ));<\/p>\n<p>if ( !empty($album) )<br \/>\n$out = nggShowAlbumTags($album);<br \/>\nelse<br \/>\n$out = nggShowGalleryTags($gallery, $template);<\/p>\n<p>return $out;<br \/>\n}<\/p>\n<p>[\/php]<\/p>\n<p>Now the nggtags option that will create a custom gallery from Tagged images can optionally include the image caption as well.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a slightly older version of NGG because I have modded it and have yet to transfer those mods to the latest version. But I just made another minor change that I wanted to document before I forget what I did. Using the [nggtags gallery=tag_selection]\u00a0 works well for showing the images from the gallery [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,24],"tags":[],"class_list":["post-891","post","type-post","status-publish","format-standard","hentry","category-blogging","category-wordpress-links"],"_links":{"self":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/comments?post=891"}],"version-history":[{"count":0,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/posts\/891\/revisions"}],"wp:attachment":[{"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/media?parent=891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/categories?post=891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howden.net.au\/thowden\/wp-json\/wp\/v2\/tags?post=891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}