Textpattern tips, tutorials and code snippets

Creating a Video Sitemap in Textpattern

Google has begun accepting sitemaps specificially for video content. If you are creating videos for your site (not just embedding from elsewhere), this is a great way to let Google know, and get them to index your content.

You can read the spec for video sitemaps in Google’s Webmaster support.

The basic setup

I post all the videos on my blog to a section called “videos”, and I store the name of the actual video file (minus the extension, .mp4) in a custom field called “video_name”. Your setup may be different, so keep that in mind when building your video sitemap. I also use the awesome plugin tru_tags to tag my videos.

With all that in place, the basic process is:

  1. Create a new section called “video_sitemap”
  2. Create a new page called “video_sitemap”
  3. Submit your sitemap to Google

The video_sitemap page template

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
       xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<txp:article_custom section="videos">
<url> 
 <loc><txp:permlink /></loc>
   <video:video>     
     <video:content_loc>http://www.norabrowndesign.com/blog/media/<txp:custom_field name="video_name" />.mp4</video:content_loc>
     <video:thumbnail_loc>http://www.norabrowndesign.com/blog/media/<txp:custom_field name="video_name" />.png</video:thumbnail_loc>
     <video:title><txp:title /></video:title>  
     <video:description><txp:excerpt /></video:description>
     <video:publication_date><txp:posted format="%FT%T-06:00" /></video:publication_date>
     <txp:if_expires><video:expiration_date><txp:expires format="%FT%T-06:00" /></video:expiration_date></txp:if_expires>
     <txp:tru_tags_from_article generatelinks="0" wraptag="video:tag" break="</video:tag><video:tag>" />
     <txp:category1 wraptag="video:category" />
     <video:family_friendly>yes</video:family_friendly>
   </video:video>
</url></txp:article_custom>
</urlset>

Customize the code above to suit your needs. In particular, note:

  • How you are generating your article list. I am using <txp:article_custom section="videos"> to grab all the articles in my videos section.
  • Where your content is located. As explained in the spec, you may indicate either the location of the actual video file, with <video:content_loc>, as I am doing (you can see that all the relevant files are in /blog/media on my server). Or, you may indicate the location of a unique video player (like a Flash player), using <video:player_loc>.
  • Your video thumbnail. I have conveniently given my thumbnails the same name as my videos, so I can use <txp:custom_field name="video_name" />.png as the name of my thumbnail file.
  • Your <video_description> source. Whether you use the <txp:body /> or <txp:excerpt /> be sure to turn off Textile or strip html some other way.
  • I put in my timezone offset manually: format="%FT%T-06:00", because I didn’t see any way to insert the colon with php’s strftime
  • Many of the later components, such as tags, categories, and family-friendliness, are optional.

Don’t forget to submit your sitemap in Google Webmaster Tools. The url will be like http://www.your-url.com/video_sitemap, for a basic Textpattern install.

2 Comments Comment feed

Spotted a little glitch at the end of the <txp:article_custom section="videos"> part:

Wrong: </txp:article>
Correct: </txp:article_custom>

Thanks Markus I fixed the typo.

Add a comment

Use Textile help to style your comments