WordPress.org

Ready to get started?Download WordPress

Forums

NextGEN Gallery Optimizer
[resolved] How to create image sitemap for nextgen gallery please anyone tell me (30 posts)

  1. cuteantonyraj
    Member
    Posted 1 year ago #

    Hi Friends im using nextgen gallery , its so nice, but i dont know how to include nexgen gallery in sitemap, please anyone help me , is nextgen galley will suitable for me or i have to use wp default gallery

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

  2. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi cuteantonyraj,

    You might like to try the WordPress SEO plugin by Yoast...

    http://wordpress.org/extend/plugins/wordpress-seo/

    XML Sitemaps
    WordPress SEO has the most advanced XML Sitemaps functionality in any WordPress plugin. Once you check the box, it automatically creates XML sitemaps and notifies Google & Bing of the sitemaps existence. These XML sitemaps include the images in your posts & pages too, so that your images may be found better in the search engines too.

    To quote the NextGEN Gallery extensions page:

    WordPress SEO. This plugin will include NextGEN Gallery images in your XML Sitemaps so they are indexed by search engines.

    Hope this helps!

    Cheers,
    Mark.

  3. cuteantonyraj
    Member
    Posted 1 year ago #

    Yes Thanks For Ur Info , How To View My Image Sitemap In WordPress SEO , Tell Me The Procedure How To Include Nextgen Gallery In WordPress SEO , Please Help Me

  4. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi cuteantonyraj,

    I've been looking into this for you, and there appears to be some issues between the two plugins at the moment. Don't worry, you're not alone!

    However, I have managed to get NextGEN Gallery's images listed in WordPress SEO's sitemaps by editing NextGEN's sitemap file at wp-content/plugins/nextgen-gallery/lib/sitemap.php (thanks to this and this).

    If you navigate to Plugins --> Editor --> NextGEN Gallery --> "nextgen-gallery/lib/sitemap.php" and replace all the code with the following, you should be all up and running...

    <?php
    /**
    * Main PHP Class for XML Image Sitemaps
    *
    * @author 		Alex Rabe
    * @version      1.0
    * @copyright 	Copyright 2011
    *
    */
    class nggSitemaps {
    
        var $images	= false;
    
        /**
         * nggSitemaps::__construct()
         *
         * @return
         */
        function __construct() {
    
            add_filter('wpseo_sitemap_urlimages', array( &$this, 'add_wpseo_xml_sitemap_images'), 10, 2);
    
        }
    
        /**
         * Filter support for WordPress SEO by Yoast 0.4.0 or higher ( http://wordpress.org/extend/plugins/wordpress-seo/ )
         *
         * @since Version 1.8.0
         * @param array $images
         * @param int $post ID
         * @return array $image list of all founded images
         */
        function add_wpseo_xml_sitemap_images( $images, $post_id )  {
    
            $this->images = $images;
    
            // first get the content of the post/page
            $p = get_post($post_id);
    
            // Backward check for older images
            $p->post_content = NextGEN_Shortcodes::convert_shortcode($p->post_content);
    
            // Don't process the images in the normal way
      		remove_all_shortcodes();
    
            // We cannot parse at this point a album, just galleries & single images
            add_shortcode( 'singlepic', array(&$this, 'add_images' ) );
            add_shortcode( 'thumb', array(&$this, 'add_images' ) );
            add_shortcode( 'nggallery', array(&$this, 'add_gallery') );
            add_shortcode( 'imagebrowser', array(&$this, 'add_gallery' ) );
            add_shortcode( 'slideshow', array(&$this, 'add_gallery' ) );
    
            // Search now for shortcodes
            do_shortcode( $p->post_content );
    
            return $this->images;
        }
    
        /**
         * Parse the gallery/imagebrowser/slideshow shortcode and return all images into an array
         *
         * @param string $atts
         * @return
         */
        function add_gallery( $atts ) {
    
            global $wpdb;
    
            extract(shortcode_atts(array(
                'id'        => 0
            ), $atts ));
    
            // backward compat for user which uses the name instead, still deprecated
            if( !is_numeric($id) )
                $id = $wpdb->get_var( $wpdb->prepare ("SELECT gid FROM $wpdb->nggallery WHERE name = '%s' ", $id) );
    
            $images = nggdb::get_gallery($id, 'pid', 'ASC', true, 1000);
    
            foreach ($images as $image) {
                $src   = $image->imageURL;
                $newimage = array();
                if ( !empty($image->title) )
                    $newimage['title'] = $image->title;
                if ( !empty($image->alttext) )
                    $newimage['alt']   = $image->alttext;
                $newimage['src'] = $image->imageURL;
                $this->images[$src] = $newimage;
            }
    
            return;
        }
    }
    $nggSitemaps = new nggSitemaps();

    Note 1: You may need to click the "Save Settings" button at SEO --> XML Sitemaps afterwards in order to re-build your sitemaps, and also clear out any caching plugins you have installed to see them update.

    Note 2: What you're looking for in your sitemaps are the image counts when you click-through to /post-sitemap.xml and /page-sitemap.xml from http://www.yoursite.com/sitemap_index.xml. The totals should now include your images from NextGEN. Also, if you look at the post/page sitemap's source code in your browser (often View --> View Source), you'll now see the full URLs for all of your images nested below each post listing.

    I hope this helps!

    Cheers,
    Mark.

  5. cuteantonyraj
    Member
    Posted 1 year ago #

    Its Not Working Giving Error Message

  6. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi cuteantonyraj,

    I've just tested the above code again on the latest plugin versions to be sure we're on the same page...

    WordPress v3.5.1
    NextGEN Gallery v1.9.12
    WordPress SEO v1.4.1

    Everything appears to be working well, however you may need to have "Picture tag (ngg_tag)" selected at SEO --> XML Sitemaps in order for your sitemap to display initially (I was getting a Not Found error for a while there).

    Hope this helps!

    Cheers,
    Mark.

  7. cuteantonyraj
    Member
    Posted 1 year ago #

    Hi Mark jeldi,

    Thanks My New Plugin Updated helped me
    i Can able to see my image sitemap in post-sitemap.xml by viewing page source , i have one doubt can we create sitemap for nextgen gallery attachment page , in google im seeing other websites nextgen gallery image attachment pages are indexed , how to do that , In My post-Sitemap.xml The Image url locating post url , not locating nextgen gallery attachment page

    for example

    <loc>http://www.cinepluz.com/gallery/actress-charmi-kaur-latest-hot-and-sexy-latest-photoshoot/</loc>
    		<lastmod>2013-03-05T08:28:12+00:00</lastmod>
    		<changefreq>weekly</changefreq>
    		<priority>0.6</priority>
    		<image:image>
    			<image:loc>http://www.cinepluz.com/wp-content/uploads/2013/02/charmi-latest-hot-and-sexy-images-in-the-black-dress-photshoot-5.jpg</image:loc>
    			<image:caption>charmi latest hot and sexy images in the black dress photshoot (5)</image:caption>
    		</image:image>

    in this sitemap file my nextgen gallery image url not targetting nextgen gallery attachment page url

    http://www.cinepluz.com/gallery/actress-charmi-kaur-latest-hot-and-sexy-latest-photoshoot/?pid=1

  8. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi cuteantonyraj,

    That's great to hear!

    I've just had a look at your site, and it looks like you're using the "Show ImageBrowser" option at Gallery --> Options --> Gallery, which causes the page to refresh (with a query string parameter appended to the URL) when a thumbnail is clicked.

    I'm not sure if it's possible for WordPress SEO to detect these pseudo-pages, as they're created on-the-fly with PHP (rather than being pulled from the database)...but you may not really need them to be included at all.

    You've mentioned you've seen other sites with these pages indexed by Google, but are you sure these pages were included in their sitemaps? You don't need a sitemap at all to get indexed. They simply help the bots find more of your content more quickly.

    Alternatively, you might like to enquire about this further, or submit a feature request at the WordPress SEO Support Forum or the NextGEN Gallery Support Forum.

    Hope this helps!

    Cheers,
    Mark.

  9. cuteantonyraj
    Member
    Posted 1 year ago #

    Hi Mark Jeldi
    Thanks For Helping Me

  10. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi cuteantonyraj,

    No worries. I'm glad I could help :)

    I've been thinking...you might not actually want your single-image imagebrowser pages indexed, since they don't have any other unique content on them. Without any text, they probably won't rank for anything anyway, and they may even drag down the rest of your site under the thin content penalty. Just a thought.

    All the best with your site!

    Cheers,
    Mark.

  11. tollywoodandhra
    Member
    Posted 1 year ago #

    Hi Mark Jeldi,

    we are using the plugin for some 2 years for all the Galleries on My website but the Only negative point i see is the images are not indexing in GOOGle Image Search ...is there any solution to solve the problem ....even after Following the Above instruction i did get the solution for the problem ...we are using sitemap using Yoast SEO Plugin....is there any solution to make some changes...For referance you can look this Url http://www.tollywoodandhra.in/

    [ Signature moderated. ]

  12. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi tollywoodandhra,

    I've just taken a look at your site, and it appears everything's working correctly. If you look at the source code of the following URL (often View --> View Source in your browser), you'll see all the individual images listed for each post...

    http://www.tollywoodandhra.in/post-sitemap13.xml

    It may also take Google a while to detect and index your sitemap (though you could try adding it in Webmaster Tools to speed up the process). If they don't come up soon, you may also have some sort of conflict with another sitemap plugin you're using called "Sitemap Generator Plugin for WordPress". You can see its output at the following address...

    http://www.tollywoodandhra.in/sitemap/

    Hope this helps!

    Cheers,
    Mark.

  13. tollywoodandhra
    Member
    Posted 1 year ago #

    Hi Mark,

    Thanks for the reply ..I have removed the plugin "Sitemap Generator Plugin for WordPress" still i dont see the images are listing in Google Images...
    Can you suggest some solution for this

    --TollywoodAndhra

  14. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi tollywoodandhra,

    Your images do appear to be indexed on my end...

    To test, go to this sitemap page:
    http://www.tollywoodandhra.in/post-sitemap13.xml

    The first image url listed in the source code of that page is as follows:
    http://www.tollywoodandhra.in/wp-content/gallery/adda-stills/adda-movie-stills-1.jpg

    If you google that image link under Google Image Search, it's the first result :)

    Hope this helps!

    Cheers,
    Mark.

  15. tollywoodandhra
    Member
    Posted 1 year ago #

    Hi

    Just tried and i dont see the images are indexed from our url...

    you can check with this url and i also see that sitemap is adding images but its not indexing in google ...

    Approx we have around 40,000 images in which 1700 are indexed

    https://www.google.co.in/search?hl=en&biw=1379&bih=880&site=imghp&tbm=isch&q=adda+movie&oq=&gs_l=#hl=en&site=imghp&tbm=isch&sa=1&q=http:%2F%2Fwww.tollywoodandhra.in%2Fwp-content%2Fgallery%2Fadda-stills%2Fadda-movie-stills-1.jpg&oq=http:%2F%2Fwww.tollywoodandhra.in%2Fwp-content%2Fgallery%2Fadda-stills%2Fadda-movie-stills-1.jpg&gs_l=img.12...27036.27036.6.27817.1.1.0.0.0.0.0.0..0.0...0.0...1c.1.11.img.XRhQZeLCyKY&bav=on.2,or.r_cp.r_qf.&bvm=bv.45921128,d.bmk&fp=e80a99ec1c79d4ce&biw=1379&bih=880

  16. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi tollywoodandhra,

    If you search your domain using Google Image Search, it returns "about 69,900 results".

    Just use the following query...

    site:http://www.tollywoodandhra.in/

    Cheers,
    Mark.

  17. tollywoodandhra
    Member
    Posted 1 year ago #

    is it possible to share your gtalk or skype id ..

  18. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi tollywoodandhra,

    It appears your issue is now resolved, but if you do require further assistance with the WordPress SEO plugin, I would suggest contacting the plugin developer (http://wordpress.org/support/plugin/wordpress-seo) as they'd have a better understanding of the internal workings.

    Cheers,
    Mark.

  19. Soft Focus
    Member
    Posted 1 year ago #

    Hi Mark I tried this, but seems that my images still arent being indexed.

    Here is my site map http://www.softfocus.co.za/photography/portfolio-sitemap.xml all my images are in this portfolio section. I updated the NG code as you said, cleared my WP super Cache and saved the site map in SEO setting again after that. Any advice you can give?

    Thanks a lot

  20. Mark Jeldi
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Soft Focus,

    I've been looking at your site, and it appears the missing images in your sitemap are all being displayed with jQuery via the Justified Image Grid plugin.

    I would imagine the WordPress SEO plugin would not be able to detect these images, as they're included dynamically instead of with regular HTML.

    I hope this helps!

    Cheers,
    Mark.

  21. tollywoodandhra
    Member
    Posted 1 year ago #

    Hi Mark..

    i took the screenshot of my webmasters sitemap and index status ....Please have a look and let me know your comment all the images are submitted Months Ago...
    http://i39.tinypic.com/okdjbp.png

  22. Soft Focus
    Member
    Posted 1 year ago #

    Thanks mark, I havent tried your solution yet, but will in the future sometime.

  23. sficht
    Member
    Posted 1 year ago #

    I'm having the same problem with my gallery images not being indexed. I currently do not use a SEO plugin (tried Yoast's but it somehow corrupted my site - probably my own customizing fault though) but just a plugin that creates a sitemap only. Would you have any hint for me how to get Google to recognize my pictures nevertheless?

  24. Michael Riegel
    Member
    Posted 1 year ago #

    Hi mark,

    I read through quite many posts now and tried quite some things to get my pictures indexed, but still it looks like that seo yoast and nextgen seem to be conflicting. Could you maybe help me out? Any idea how I can get the images indexed? The site is captain-racket.de/Squash-blog.

    Thanks a lot.
    Michael

  25. BajcepsKulinarny
    Member
    Posted 1 year ago #

    Kello Mark Jeldi,
    I did all the things you wrote above, but still get 0 images in my sitemaps. Can you please give me a hint what went wrong ?
    Id appreciate your help.
    http://www.zeglujznami.pl/ngg_tag-sitemap.xml

    e.g.
    http://www.zeglujznami.pl/ngg_tag/mazury/

    btw. wordpress seo generated only 4 galleries, while there are at least 9
    http://www.zeglujznami.pl/galeria-zeglarska/

    Thanks, anyone ?

  26. hodyshoran
    Member
    Posted 1 year ago #

    Hello Everyone, hello Mark,

    we have a music magazine at http://www.tribe-online.de and have problems finding our pictures back on Google. We use your great plugin to show off our concert shots.

    It happens that we did a concert review on NAS, but when the author later checked google, only the article pic showed up, which was set without NextGen (nas site:http://www.tribe-online.de).

    We use Google XML Sitemaps and wpSEO.

    Thanks Patrik

  27. Konstantin Ryabenko
    Member
    Posted 9 months ago #

    Hi Everyone,

    I use:
    Wordpress 3.8
    WordPress SEO 1.4.20
    NextGEN Gallery 2.0.30

    I have a little trouble with my sitemap.
    http://yana-butenko.com/blog-type-sitemap.xml

    It doesn't include all images from NextGEN Gallery which added to post. For adding images in my posts I use "NextGEN Basic SinglePic" and "NextGEN Basic Thumbnails". As a result my sitemap includes all singlepic and all preview singlepic, also it includes my post's miniature.
    But the sitemap not includes all images added through NextGEN Basic Thumbnails.

    If you'll see my sitemap, you can see that the first string of the sitemap shows that post has 3 images. There are 6 images in this post really. Here is code:

    <url>
    <loc>http://yana-butenko.com/ru/blogs/37-moskovskaya-mezhdunarodnaya-vyistavka-obrazovanie-i-karera-21-vek</loc>
    <lastmod>2013-10-06T19:10:39+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.6</priority>
    <image:image>
    <image:loc>http://yana-butenko.com/images/ngg_featured/20130228_00.jpg</image:loc>
    </image:image>
    <image:image>
    <image:loc>http://yana-butenko.com/nextgen-attach_to_post/preview/id--1548</image:loc>
    </image:image>
    <image:image>
    <image:loc>http://yana-butenko.com/images/gallery/blog20130228/20130228_01.jpg</image:loc>
    <image:title>blog20130228</image:title>
    <image:caption>20130228_01</image:caption>
    </image:image>
    </url>

    Mark,
    I tried to use your code for sitemap.php but then the sitemap includes preview singlepic and post's miniature, but not includes fullscreen singlepic. Here is code:

    <url>
    <loc>http://yana-butenko.com/ru/blogs/37-moskovskaya-mezhdunarodnaya-vyistavka-obrazovanie-i-karera-21-vek</loc>
    <lastmod>2013-10-06T19:10:39+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.6</priority>
    <image:image>
    <image:loc>http://yana-butenko.com/images/ngg_featured/20130228_00.jpg</image:loc>
    </image:image>
    <image:image>
    <image:loc>http://yana-butenko.com/nextgen-attach_to_post/preview/id--1548</image:loc>
    </image:image>
    </url>

    Help me, please. How can I add images which added through NextGEN Basic Thumbnails to my sitemap?

    Thanks...

  28. Scorpious
    Member
    Posted 7 months ago #

    I am using Google sitemap for images. I have modified image-sitemap.php file to include nextgen 2.0 shortcodes. Please note at this point the code only respects "album_ids" "gallery_ids", and "image_ids". I have not coded for "exclusions" and "category" attributes etc. Please not I am coding in PHP after a decade (so there is room for improvement).

    <?php
    /*
    Plugin Name: Google XML Sitemap for Images
    Plugin URI: http://www.labnol.org/internet/google-image-sitemap-for-wordpress/14125/
    Description: This plugin will generate a XML Image Sitemap for your WordPress blog. Open the <a href="tools.php?page=image-sitemap-generate-page">settings page</a> to create your image sitemap.
    Author: Amit Agarwal
    Version: 2.1.3
    Author URI: http://www.labnol.org/
    */
    
    add_action('admin_menu', 'image_sitemap_generate_page');
    
    function image_sitemap_generate_page() {
        if(function_exists('add_submenu_page')) add_submenu_page('tools.php', __('Image Sitemap'),
    	    __('Image Sitemap'), 'manage_options', 'image-sitemap-generate-page', 'image_sitemap_generate');
    }
    
    /* @author  VJTD3 <http://www.VJTD3.com> */
    function IsImageSitemapWritable($filename) {
        if(!is_writable($filename)) {
            if(!@chmod($filename, 0666)) {
                $pathtofilename = dirname($filename);
                if(!is_writable($pathtofilename)) {
                    if(!@chmod($pathtoffilename, 0666)) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
    
    function EscapeXMLEntities($xml) {
        return str_replace(array('&', '<', '>', '\'', '"'), array('&', '<', '>', '&apos;', '&quot;'), $xml);
    }
    
    function image_sitemap_generate () {
      if ($_POST ['submit']) {
        $st = image_sitemap_loop ();
         if (!$st) {
    echo '<br /><div class="error"><h2>Oops!</h2><p>The XML sitemap was generated successfully but the  plugin was unable to save the xml to your WordPress root folder at <strong>' . $_SERVER["DOCUMENT_ROOT"] . '</strong>.</p><p>Please ensure that the folder has appropriate <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">write permissions</a>.</p><p> You can either use the chmod command in Unix or use your FTP Manager to change the permission of the folder to 0666 and then try generating the sitemap again.</p><p>If the issue remains unresolved, please post the error message in this <a target="_blank" href="http://wordpress.org/tags/google-image-sitemap?forum_id=10#postform">WordPress forum</a>.</p></div>';
    exit();
    }
    ?>
    
    <div class="wrap">
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
    if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
    <div style="width:800px; padding:10px 20px; background-color:#eee; font-size:.95em; font-family:Georgia;margin:20px">
      <h2>XML Sitemap for Images</h2>
      <?php $sitemapurl = get_bloginfo('url') . "/sitemap-image.xml"; ?>
      <p>The <a target="_blank" href="<?php echo $sitemapurl; ?>">XML Sitemap</a> was generated successfully and you can <a target="_blank" href="http://www.google.com/webmasters/sitemaps/ping?sitemap=<?php echo $sitemapurl; ?>">ping Google</a> to inform them about your updated sitemap.</p>
      <p>This WordPress Plugin is written by <a href="http://www.labnol.org/about/">Amit Agarwal</a> of <a href="http://www.labnol.org/">Digital Inspiration</a>. For feedback or suggestions on improving this plugin, please send me an email at amit@labnol.org</p>
      <p><a href="https://twitter.com/labnol" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @labnol</a>
        <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fdigital.inspiration&send=false&layout=button_count&width=300&show_faces=false&action=recommend&colorscheme=light&font=arial&height=24&appId=197498283654348" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:20px;" allowTransparency="true"></iframe>
      </p>
    </div>
    <?php } else { ?>
    <div class="wrap">
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
    <div style="width:800px; padding:10px 20px; background-color:#eee; font-size:.95em; font-family:Georgia;margin:20px">
      <h2>XML Sitemap for Images</h2>
      <p>Sitemaps are a way to tell Google and other search engines about web pages, images and video content on your site that they may otherwise not discover. </p>
      <form id="options_form" method="post" action="">
        <div class="submit">
          <input type="submit" name="submit" id="sb_submit" value="Generate Image Sitemap" />
        </div>
      </form>
      <p>Click the button above to generate a Image Sitemap for your website. Once you have created your Sitemap, you should submit it to Google using Webmaster Tools. </p>
      <p>You may also want to create separate <a href="http://wordpress.org/extend/plugins/xml-sitemaps-for-videos/">Video Sitemap</a> and <a href="http://wordpress.org/extend/plugins/google-mobile-sitemap/">Mobile Sitemap</a> for improving your site's visibility in Google.</p>
      <p>This WordPress Plugin is written by <a href="http://www.labnol.org/about/">Amit Agarwal</a> of <a href="http://www.labnol.org/">Digital Inspiration</a>. </p>
    </div>
    <?php }
    }
    
    function ks_get_ngg_album_ID_Matches($content) {
    	return  ks_getIDs_for_ngg_tag($content, 'album_ids');
    }
    
    function ks_get_ngg_gallery_ID_Matches($content) {
    	return  ks_getIDs_for_ngg_tag($content, 'gallery_ids');
    }
    
    function ks_getIDs_for_ngg_tag($content, $tag){
    	$search_expr = '/[tagname]=("|\')?[0-9]+(,[0-9]+)*("|\')?/';
    	$search_expr = str_replace("[tagname]", $tag, $search_expr);
    	$search_delimited_number_exp = '/[0-9]+(,[0-9]+)*/';
    	if(preg_match_all($search_expr, $content, $matches, PREG_SET_ORDER)) {
    		$allTagIDs='';
    		foreach($matches as $match) {
    			preg_match($search_delimited_number_exp, $match[0], $del_numbers, PREG_OFFSET_CAPTURE);
    			if ($del_numbers[0][0]!=''){
    				$allTagIDs .= $del_numbers[0][0] . ',';
    			}
    		}
    	}
    	return rtrim($allTagIDs, ',');
    }
    
    function ks_get_image_Tags_for_gallery_IDs($ids, $imgTemplateNode){
    	global $wpdb;
    	// get gallery titles according to id's we got
    	//$query_titles = "SELECT title, gid FROM wp_ngg_gallery WHERE gid IN('".$ids."')";
    	$FinalGalleryImageTags='';
    	$galleries = $wpdb->get_results ("SELECT gid, name, title, galdesc, path FROM {$wpdb->prefix}ngg_gallery
    		WHERE gid IN (".$ids.")"); // get gallery path
    
    	if (empty ($galleries)) {
    		return ''; //no pics? do nothing
    	} else { //pics found!
    		$domain = get_bloginfo('url');
    		foreach ($galleries as $gallery) {
    			$imgNodeGallery = str_replace('[img_caption]', $gallery->name.' : '. $gallery->galdesc.' [img_caption]', $imgTemplateNode);
    			$imgBaseUrl = $domain.'/'. $gallery->path .'/';
    			$pics = $wpdb->get_results ("SELECT filename, description, alttext FROM {$wpdb->prefix}ngg_pictures
    				WHERE galleryid = ".$gallery->gid); //get fileinformation , should be made with one query using JOINS ???
    
    			if (empty ($pics)) {
    				    return '';
    			} else { //pics found!
    				foreach ($pics as $pic) {
    					//return 'loompa-'.$imgNodeGallery.'</br>';
    					$currImageTag =  str_replace('[img_caption]', $pic->alttext, $imgNodeGallery);
    					$currImageTag =  str_replace('[img_title]', $pic->description, $currImageTag);
    					$currImageTag =  str_replace('[img_url]', ($imgBaseUrl . $pic->filename), $currImageTag);
    
    					$FinalGalleryImageTags .=  $currImageTag;
    				}
    			}
    		}
    	}
    	return $FinalGalleryImageTags;
    }
    
    function ks_add_ngg_tags($post_content){
    	global $wpdb;
    		// ngg code - start
    		$imgNode = "<image:image><image:loc>[img_url]</image:loc><image:title>[img_title]</image:title><image:caption>[img_caption]</image:caption><image:geo_location>[img_geo_location]</image:geo_location></image:image>";
    		$imgNode = str_replace('[img_geo_location]', 'New York City, New York, USA', $imgNode);
    
    		$allImageTags='';
    	       if (strpos($post_content, '[ngg_images') !== FALSE) {
    			$album_ids = ks_get_ngg_album_ID_Matches($post_content);
    			if ($album_ids!='') {
    				// get the needed albums gallery id's
    				$albumRows = $wpdb->get_results ("SELECT sortorder, albumdesc FROM {$wpdb->prefix}ngg_album WHERE id IN (".$album_ids.")");
    				if (empty ($albumRows)) {
    				    return '';
    				}
    				else{
    
    					foreach ($albumRows as $albumRow) {
    						$imgNodeAlbum = str_replace('[img_caption]', $albumRow->albumdesc.' : [img_caption]', $imgNode);
    						$arrSortOrder = unserialize($albumRow->sortorder);
    						$gallery_delim_ids = '';
    						for($i=0; $i < count($arrSortOrder); $i++){
    							if($i != (count($arrSortOrder)-1)){
    								$gallery_delim_ids .= (int)$arrSortOrder[$i].", ";
    							}elseif($i == (count($arrSortOrder)-1)){
    								$gallery_delim_ids .= (int)$arrSortOrder[$i]."";
    							}
    						}
    
    						//$allImageTags .= "******** album ***".$album_ids."****GALLERY*******". $gallery_delim_ids."<br/>".$imgNodeAlbum."<br/>";
    						$allImageTags .= ks_get_image_Tags_for_gallery_IDs($gallery_delim_ids, $imgNodeAlbum);
    						//$content .= '<img src="http://'.$domain.'/'. $path->path .'/'. $pic->filename.'"><br> ';
    					}
    
    				}
    
    			}
    			else {
    				$gallery_ids = ks_get_ngg_gallery_ID_Matches($post->post_content);
    				$allImageTags .= ks_get_image_Tags_for_gallery_IDs($gallery_ids, $imgNode);
    			}
    
    		}
    		// ngg code - end
    	return $allImageTags;
    }
    
    function image_sitemap_loop () {
    	global $wpdb;
    
    	$posts = $wpdb->get_results ("SELECT id, post_parent, post_content, guid, post_type FROM $wpdb->posts wposts
                                         WHERE ((wposts.post_type = 'post') and (wposts.post_status='publish'))
                                         OR    ((wposts.post_type = 'page') and (wposts.post_status='publish'))
    
                                         OR    ((wposts.post_type = 'attachment') and (wposts.post_status='inherit'))
                                               and ((wposts.post_mime_type = 'image/jpg') or (wposts.post_mime_type = 'image/gif')
                                               or (wposts.post_mime_type = 'image/jpeg') or (wposts.post_mime_type = 'image/png'))
    
                                         ");
    
    	if (empty ($posts)) {
    	   return false;
    	} else {
              $xml  = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
              $xml .= '<!-- Created by (http://wordpress.org/extend/plugins/google-image-sitemap/) -->'."\n";
              $xml .= '<!-- Generated-on="'.date("F j, Y, g:i a").'" -->'."\n";
              $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'."\n";
    
            foreach($posts as $post) {
    		$img='';
                    if($post->post_type == "attachment") {
    			if($post->post_parent != 0) {
    				$images[$post->post_parent][] = $post->guid;
    			}
                    }
    		else if(preg_match_all("/[\'\"](http:\/\/.[^\'\"]+\.(?:jpe?g|png|gif))[\'\"]/ui", $post->post_content, $matches, PREG_SET_ORDER)) {
    			foreach($matches as $match) {
    				$images[$post->id][] = $match[1];
    			}
                    }
    
    	        $img = ks_add_ngg_tags($post->post_content);
    		if ($img !=''){
    			$xml .= "<url><loc>" . EscapeXMLEntities($post->guid) . "</loc>" . $img . "</url>";
    		}
    	}     
    
    	foreach($images as $k => $v) {
                            $img='';
    			$permalink = get_permalink($k);
    			if ( ! empty ( $permalink ) ) {
    				$img = "<image:image><image:loc>".implode("</image:loc></image:image><image:image><image:loc>", $v)."</image:loc></image:image>";
                                    if ($img !=''){
    					$xml .= "<url><loc>" . EscapeXMLEntities($permalink) . "</loc>" . $img . "</url>";
    				}
    			}
    	}
    
             $xml .= "\n</urlset>";
            }
    
            $image_sitemap_url = $_SERVER["DOCUMENT_ROOT"].'/sitemap-image.xml';
            if(IsImageSitemapWritable($_SERVER["DOCUMENT_ROOT"]) || IsImageSitemapWritable($image_sitemap_url)) {
                if(file_put_contents($image_sitemap_url, $xml)) {
                       return true;
                }
            }
       return false;
     }
    ?>
  29. Scorpious
    Member
    Posted 7 months ago #

    Plus I am working to make the same work for WP-SEO. I found "\plugins\nextgen-gallery\products\photocrati_nextgen\modules\ngglegacy\lib\sitemap.php" where I added code to take new shortcodes.
    But it is not working. I am not sure how WP-SEO makes a call to this file. If someone can shed some light on that then I can come up with a solution.
    A unit test with dummy post-content (in a variable) is working with the code I have. Just need to know who it gets triggered from WP-SEO. Would appreciate some help.

  30. Scorpious
    Member
    Posted 7 months ago #

    I think I got WP-SEO working. It was a problem with NextGen Sitemap.php

    Here is the updated code for "\plugins\nextgen-gallery\products\photocrati_nextgen\modules\ngglegacy\lib\sitemap.php"

    Please note that this is for nextgen 2.0 shortcodes. Also at this point the code only respects "album_ids" "gallery_ids", and "image_ids". I have not coded for "exclusions" and "category" attributes etc.

    <?php
    /**
    * Main PHP Class for XML Image Sitemaps
    *
    * @author 		Alex Rabe
    * @version      1.0
    * @copyright 	Copyright 2011
    *
    */
    class nggSitemaps {
    
        var $images	= array();
    
        /**
         * nggSitemaps::__construct()
         *
         * @return
         */
        function __construct() {
    
            add_filter('wpseo_sitemap_urlimages', array( &$this, 'add_wpseo_xml_sitemap_images'), 10, 2);
    
        }
    
        /**
         * Filter support for WordPress SEO by Yoast 0.4.0 or higher ( http://wordpress.org/extend/plugins/wordpress-seo/ )
         *
         * @since Version 1.8.0
         * @param array $images
         * @param int $post ID
         * @return array $image list of all founded images
         */
        function add_wpseo_xml_sitemap_images( $images, $post_id )  {
    
            $this->images = $images;
    
            // first get the content of the post/page
            $p = get_post($post_id);
    
            // Backward check for older images
            $p->post_content = NextGEN_Shortcodes::convert_shortcode($p->post_content);
    
            // Don't process the images in the normal way
      		remove_all_shortcodes();
    
            // We cannot parse at this point a album, just galleries & single images
    		C_NextGen_Shortcode_Manager::add( 'singlepic', array(&$this, 'add_images' ) );
    		C_NextGen_Shortcode_Manager::add( 'thumb', array(&$this, 'add_images' ) );
    		C_NextGen_Shortcode_Manager::add( 'nggallery', array(&$this, 'add_gallery') );
    		C_NextGen_Shortcode_Manager::add( 'imagebrowser', array(&$this, 'add_gallery' ) );
    		C_NextGen_Shortcode_Manager::add( 'slideshow', array(&$this, 'add_gallery' ) );
    
            // KS-start: Code to accept new shortcode
            C_NextGen_Shortcode_Manager::add( 'ngg_images', array(&$this, 'add_ngg_images_tag' ) );
            // KS-end: Code to accept new shortcode
    
            // Search now for shortcodes
            do_shortcode( $p->post_content );
    
            return $this->images;
        }
    
        /**
         * Parse the gallery/imagebrowser/slideshow shortcode and return all images into an array
         *
         * @param string $atts
         * @return
         */
        function add_gallery( $atts ) {
    
            global $wpdb;
    
            extract(shortcode_atts(array(
                'id'        => 0
            ), $atts ));
    
            // backward compat for user which uses the name instead, still deprecated
            if( !is_numeric($id) )
                $id = $wpdb->get_var( $wpdb->prepare ("SELECT gid FROM $wpdb->nggallery WHERE name = '%s' ", $id) );
    
            $images = nggdb::get_gallery($id, 'pid', 'ASC', true, 1000);
    
            foreach ($images as $image) {
                $newimage = array();
                $newimage['src']   = $newimage['sc'] = $image->imageURL;
                if ( !empty($image->title) )
                    $newimage['title'] = $image->title;
                if ( !empty($image->alttext) )
                    $newimage['alt']   = $image->alttext;
                $this->images[] = $newimage;
            }
    
            return '';
        }
    
        /**
         * Parse the single image shortcode and return all images into an array
         *
         * @param array $atts
         * @return
         */
        function add_images( $atts ) {
    
            extract(shortcode_atts(array(
                'id'        => 0
            ), $atts ));
    
            // make an array out of the ids (for thumbs shortcode))
            $pids = explode( ',', $id );
    
            // Some error checks
            if ( count($pids) == 0 )
                return;
    
            $images = nggdb::find_images_in_list( $pids );
    
            foreach ($images as $image) {
                $newimage = array();
                $newimage['src']   = $newimage['sc'] = $image->imageURL;
                if ( !empty($image->title) )
                    $newimage['title'] = $image->title;
                if ( !empty($image->alttext) )
                    $newimage['alt']   = $image->alttext;
                $this->images[] = $newimage;
            }
    
            return '';
        }
    
    // KS-start: Code to accept new shortcode
    
        function add_ngg_images_tag( $atts ) {
    
            global $wpdb;
    
    	extract(shortcode_atts(array('image_ids' => 0,  'album_ids' => 1, 'gallery_ids' => 2), $atts ));
    
    	if ($image_ids!='' and $image_ids!=0){
    		// make an array out of the ids (for thumbs shortcode))
    		$pids = explode( ',', $image_ids );
    		// Some error checks
    		if ( count($pids) == 0 )
    			return;
    		$images = nggdb::find_images_in_list( $pids );
    		nggSitemaps::add_to_global_images_array($images);
    		return '';
    	}
    
    	if ($album_ids!='' and $album_ids!=0)
    		$gallery_ids = nggSitemaps::get_galleryIDs_from_albumID($album_ids);
    
    	if ($gallery_ids=='' or $gallery_ids==0)
    		return '';
    
    	$gallery_id_arr = explode(',',$gallery_ids);
    
    	foreach ($gallery_id_arr as $id) {
    		$images = nggdb::get_gallery($id, 'pid', 'ASC', true, 1000);
    		nggSitemaps::add_to_global_images_array($images);
    	}
    
            return '';
        }
    
       function get_galleryIDs_from_albumID($album_ids){
    
    	global $wpdb;
    	$albumRows = $wpdb->get_results ("SELECT sortorder FROM {$wpdb->prefix}ngg_album WHERE id IN (".$album_ids.")");
            $gallery_delim_ids = '';
    	if (empty ($albumRows)) {
    		return '';
    	}
    	else{
    		foreach ($albumRows as $albumRow) {
    			$arrSortOrder = unserialize($albumRow->sortorder);
    
    			for($i=0; $i < count($arrSortOrder); $i++){
    				if($i != (count($arrSortOrder)-1)){
    					$gallery_delim_ids .= (int)$arrSortOrder[$i].", ";
    				}elseif($i == (count($arrSortOrder)-1)){
    					$gallery_delim_ids .= (int)$arrSortOrder[$i]."";
    				}
    			}
    		}
    
    	}
    	return $gallery_delim_ids;
       }
    
       function add_to_global_images_array($images){
    	foreach ($images as $image) {
                $newimage = array();
                $newimage['src']   = $newimage['sc'] = $image->imageURL;
                if ( !empty($image->title) )
                    $newimage['title'] = $image->title;
                if ( !empty($image->alttext) )
                    $newimage['alt']   = $image->alttext;
                $this->images[] = $newimage;
    	}
       }
    
    // KS-end: Code to accept new shortcode
    
    }
    $nggSitemaps = new nggSitemaps();

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags