Adding FAlbum URLs to XML-Sitemap WordPress Plugin

As I mentioned on my previous post yesterday about Fixing FAlbum Plugin that I'm trying to add support for Google XML Sitemaps Plugin to FAlbum so that all URLs including albums, photos and tags would be added to Blog’s Sitemap which would be crawled by Google, Yahoo and MSN .
Actually, Google XML Sitemaps Plugin made the job much easier by providing simple WordPress add_action() to add the URLs, so you only need to add one function inside 'wp-content/plugins/falbum/wordpress-falbum-plugin.php' to accomplish the job !

Edit file wp-content/plugins/falbum/wordpress-falbum-plugin.php and add these lines before the add_action lines

  1.  
  2. function addto_sitemaps(){
  3.         global $falbum;
  4.        
  5.         #add FAlbum url to Sitemaps
  6.         function FA_xml_url($pfx=){
  7.                 if( ($FA_xml_go=&GoogleSitemapGenerator::GetInstance()) == null) return;
  8.                 $FA_xml_go->AddUrl( get_option(’siteurl').$GLOBALS['falbum']->create_url($pfx) , time() , "always", 0.8);
  9.         }
  10.         #creates extra pages depending on the limit you set for
  11.         #photos and albums per page
  12.         function FA_xml_pages($tot, $limit , $pfx = ){
  13.            $pages = ceil( $tot / $limit);
  14.            for($i=1; $i <= $pages; $i++)
  15.                         FA_xml_url(   $pfx.'page/'.$i.'/' );
  16.         }
  17.         #creates photos urls
  18.         function FA_xml_get_photos(  &$photos , $pfx , $type = 'photoset'){
  19.                 global $falbum;
  20.                 $photo_title_array = array();
  21.                 for( $i=0, $max=count($photos[$type]['photo']); $i < $max ; $i++){
  22.                         $photo = $photos[$type]['photo'][$i];
  23.                         $photo_id = $photo['id'];
  24.                         $photo_title = $photo['title'];
  25.                        
  26.                         $photo_link = $falbum->_get_link_title($photo_title, $photo_id, $photo_title_array);
  27.                         $p = ceil(($i+1)/$falbum->options['photos_per_page']);
  28.                         FA_xml_url(  "{$pfx}page/{$p}/photo/{$photo_link}/");
  29.                 }
  30.         }
  31.         #disable administrator user_level to hide secret sets
  32.         $GLOBALS['user_level'] = 0;
  33.  
  34.         #getting Flickr albums
  35.         $albums = $falbum->_call_flickr_php('flickr.photosets.getList', array ("user_id" => $falbum->options['nsid']));
  36.         #creating main album extra pages
  37.         FA_xml_pages(  count($albums['photosets']['photoset']), $falbum->options['albums_per_page'] );
  38.        
  39.         #inserting recent photos pages
  40.         $pfx = "show/recent/";
  41.         FA_xml_url( $pfx);
  42.         $photos = $falbum->_call_flickr_php('flickr.photos.search', array ('user_id' => $falbum->options['nsid'], ’sort' => 'date-taken-desc'));
  43.        
  44.         $num = count($photos);
  45.         #get recent pages
  46.         FA_xml_pages(   ($falbum->options['number_recent'] == -1 ? $num : $falbum->options['number_recent']) , $falbum->options['photos_per_page'] , $pfx);
  47.         #get recent photos
  48.         FA_xml_get_photos(   $photos , $pfx , 'photos');
  49.  
  50.         #to avoid creating duplicates when creating urls
  51.         $photo_title_array = array();
  52.         #creating albums urls
  53.         foreach($albums['photosets']['photoset'] as $album){
  54.                 $id = $album['id'];
  55.                 $title = $falbum->_unhtmlentities($album['title']['_content']);
  56.                 $link_title = $falbum->_get_link_title($title, $id, $photo_title_array);
  57.                 $pfx = "album/{$link_title}/";
  58.                 FA_xml_url(  $pfx);
  59.                 #creating album extra pages
  60.                 FA_xml_pages(   $album['photos'] , $falbum->options['photos_per_page'] , $pfx);
  61.                
  62.                 #getting album photos
  63.                 $photos = $falbum->_call_flickr_php('flickr.photosets.getPhotos', array ("photoset_id" => $album['id']));
  64.                 FA_xml_get_photos(   $photos , $pfx);
  65.                
  66.        
  67.         }
  68.        
  69.        
  70.         #inserting tags pages
  71.         FA_xml_url(  "show/tags/");
  72.         $tags = $falbum->_call_flickr_php('flickr.tags.getListUserPopular', array ('count' => '500′, user_id => $falbum->options['nsid']));
  73.        
  74.         foreach( $tags['who']['tags']['tag'] as $tag ){
  75.                 $pfx = "tags/{$tag['_content']}/";
  76.                 FA_xml_url(  $pfx);
  77.                
  78.                
  79.                 #getting tag photos
  80.                 $photos = $falbum->_call_flickr_php('flickr.photos.search', array ('user_id' => $falbum->options['nsid'], 'tags' => $tag['_content'], 'tag_mode' => 'all'));
  81.                 $num = count($photos);
  82.                 #tag pages
  83.                 FA_xml_pages(   $num,  $falbum->options['photos_per_page'], $pfx);
  84.                
  85.                 FA_xml_get_photos(   $photos , $pfx, 'photos');
  86.                
  87.         }
  88. }
  89. add_action("sm_buildmap","addto_sitemaps");
  90.  

you see a working preview of my Sitemap

*update 10Dec2007 : fixed photo links 302 redirection*


Tags :

This entry was posted on Thursday, November 22nd, 2007 at 2:19 pm and is filed under Programs, Solutions. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

9 Responses to “Adding FAlbum URLs to XML-Sitemap WordPress Plugin”

  1. What is a URL? Says:

    Can the sitemap map things that are outside of WP? Photos, for instance?

  2. wkarim Says:

    @whatisaurl : it’s a question to ask xml-sitemaps plugin support. however, you can add static pages manually and you don't need to add photos to sitemaps unless it’s for Google images search.

  3. What is a URL? Says:

    The static pages won't get overwritten when I update?

  4. wkarim Says:

    @whatisaurl : xml-sitemaps plugin store manually added static pages in the database so as far as you did not make any changes in the DB during the upgrade it will not change

  5. Matt Says:

    Hi! Whenever I paste your above script into wp-content/plugins/falbum/wordpress-falbum-plugin.php, it takes down my blog… running falbum 0.7.1 and sitemaps 3.0.3. Any suggestions? is it a pathing issue? (the blog sits at /blog, but it is actually at the root).

  6. wkarim Says:

    @Matt
    Please copy and paste the code again, or replace all unicode (’‘) with '

  7. Matt Says:

    Thanks, I'll try– also, I didn't do your other updates from your other post… is it necessary to do that as well, or can I just do this one?

  8. wkarim Says:

    @Matt
    Welcome! you don't need to add the fixes from the other post for adding falbum to sitemap to work.

  9. Fixing Flickr FAlbum rewrite rules, thumbnails, javascripts and more … :: GadElKareem Says:

    [...] to get xml-sitemaps and FAlbum to play nice together…not sure I have the time to do it! Adding FAlbum URLs to XML-Sitemap WordPress Plugin [...]

 

Leave a Reply


 Top