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

function addto_sitemaps(){
	global $falbum;
	#add FAlbum url to Sitemaps
	function FA_xml_url($pfx=''){
		if( ($FA_xml_go=&GoogleSitemapGenerator::GetInstance()) == null) return;
		$FA_xml_go->AddUrl( _option('siteurl').$GLOBALS['falbum']->create_url($pfx) , time() , "always", 0.8);
	# extra pages depending on the limit you set for 
	#photos and albums per page
	function FA_xml_pages($tot, $limit , $pfx = '' ){
	   $pages = ceil( $tot / $limit);
	   for($i=1; $i <= $pages; $i++)
			FA_xml_url(   $pfx.'page/'.$i.'/' );
	# photos urls
	function FA_xml_get_photos(  &$photos , $pfx , $type = 'photoset'){
		global $falbum;
		$photo_title_array = array();
		for( $i=0, $max=count($photos[$type]['photo']); $i < $max ; $i++){
			$photo = $photos[$type]['photo'][$i];
			$photo_id = $photo['id'];
			$photo_title = $photo['title'];
			$photo_link = $falbum->_get_link_title($photo_title, $photo_id, $photo_title_array);
			$p = ceil(($i+1)/$falbum->options['photos_per_page']);
			FA_xml_url(  "{$pfx}page/{$p}/photo/{$photo_link}/");
	# administrator user_level to hide secret sets
	$GLOBALS['user_level'] = 0;

	# Flickr albums
	$albums = $falbum->_call_flickr_php('flickr.photosets.getList', array ("user_id" => $falbum->options['nsid']));
	# main album extra pages
	FA_xml_pages(  count($albums['photosets']['photoset']), $falbum->options['albums_per_page'] );
	# recent photos pages
	$pfx = "show/recent/";
	FA_xml_url( $pfx);
	$photos = $falbum->_call_flickr_php('', array ('user_id' => $falbum->options['nsid'], 'sort' => 'date-taken-desc'));
	$num = count($photos);
	#get recent pages
	FA_xml_pages(   ($falbum->options['number_recent'] == -1 ? $num : $falbum->options['number_recent']) , $falbum->options['photos_per_page'] , $pfx);
	#get recent photos
	FA_xml_get_photos(   $photos , $pfx , 'photos');

	#to avoid  duplicates when  urls
	$photo_title_array = array();
	# albums urls
	foreach($albums['photosets']['photoset'] as $album){
		$id = $album['id'];
		$title = $falbum->_unhtmlentities($album['title']['_content']);
		$link_title = $falbum->_get_link_title($title, $id, $photo_title_array);
		$pfx = "album/{$link_title}/";
		FA_xml_url(  $pfx);
		# album extra pages
		FA_xml_pages(   $album['photos'] , $falbum->options['photos_per_page'] , $pfx);
		#getting album photos
		$photos = $falbum->_call_flickr_php('flickr.photosets.getPhotos', array ("photoset_id" => $album['id']));
		FA_xml_get_photos(   $photos , $pfx);
	#inserting tags pages
	FA_xml_url(  "show/tags/");
	$tags = $falbum->_call_flickr_php('flickr.tags.getListUserPopular', array ('count' => '500', user_id => $falbum->options['nsid']));
	foreach( $tags['who']['tags'][''] as $ ){
		$pfx = "tags/{$['_content']}/";
		FA_xml_url(  $pfx);
		#getting  photos
		$photos = $falbum->_call_flickr_php('', array ('user_id' => $falbum->options['nsid'], 'tags' => $['_content'], '_mode' => 'all'));
		$num = count($photos);
		# pages
		FA_xml_pages(   $num,  $falbum->options['photos_per_page'], $pfx);
		FA_xml_get_photos(   $photos , $pfx, 'photos');

you see a working preview of my Sitemap

*update 10Dec2007 : fixed photo links 302 redirection*

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

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

  • The static pages won’t get overwritten when I update?

  • @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

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

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

  • 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?

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

  • Pingback: Fixing Flickr FAlbum rewrite rules, thumbnails, javascripts and more … :: GadElKareem()

  • I am unable to cut + paste your code as it throws up unusual characters. I’ve tried visual browsers like Firefox and also Lynx.

    Can you please help ?

  • @coalman
    please use text file to copy your code

  • tamedcats


    I tried to add image but I don’t know how to do this
    Can anyone be kind to tell me how?

    thanks a lot