Blogger Label List for FTP Published Blogs

I use Blogger for this blog, mainly because it is easy to use. One of the features of the new Blogger that I like is the ability to add labels to posts, but because I publish via FTP there is no way to use the labels widget that is available to users of the new Blogger that publish to Blogspot blogs. Well I really wanted to be able to list all the labels I use so there is easy access to posts by categories so I came up with a quick little PHP script to do just that.

First you have to know that when the new Blogger publishes the labels to a server via FTP it creates a folder called labels and publishes all the label pages to that folder. It also makes the file names the same as the label. This makes it easy to create a script to read all the file names in the labels folder, and output the names.

Here is a copy of the PHP script that you can use to read all of the .html files in the labels folder and output them as an unordered list. Save it and place it in the labels folder of your web server. In the script it does not include the php script in the list, if you save the script with a different name than “labelslist.php” then make sure you change filename in the script.

Update: Download the code for the labels list instead of copying and pasting. Download




if ($handle = opendir($labelsdir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "index.html" && $file != "labelslist.php" && ereg(".html$",$file)) {
$files[$fkey]['name'] = $file; $fkey++;

echo '<ul>';
foreach ($files as $key=>$value) {
echo '<li><a href="/labels/'.$files[$key]['name'].'">'.ucwords(substr($files[$key]['name'], 0, -5)).'</a></li> ';
echo '</ul>';


Now if you have setup your server to process .html files as php then your server will process PHP includes that you have in your Blogger template file. Find the location in your Blogger template that you want to include the labels list and do a simple PHP include

<?php include_once($_SERVER['DOCUMENT_ROOT']."/labels/labelslist.php"); ?>

and republish. Your label list should now appear on your FTP published Blogger blog.

The script outputs an unordered list so you might want to style the list so it is similar to the rest of your blog. It is also possible to make this list look more like a tag cloud. If people want to know how to do that leave a comment and I will add another post to help create a tag cloud style list. Happy blogging!

EDIT: Just noticed that when Blogger creates the label pages that have spaces in the names it is properly encoding them with a %20 as the space. To stop the %20 from showing up and actually have a space modify the line in the code from this:

echo '<li><a href="/labels/'.$files[$key]['name'].'">'.ucwords(substr($files[$key]['name'], 0, -5)).'</a></li> ';


echo '<li><a href="/labels/'.$files[$key]['name'].'">'.ucwords(substr(urldecode($files[$key]['name']), 0, -5)).'</a></li> ';
That should decode the %20 so a space actually shows up on the link.

EDIT: The change Blogger did has turned into more of a pain in the neck than it should have been. Check out this post titled “Spaces in Blogger Labels – A Change” about why. Anyways, probably the best solution is to not use spaces in your labels but use a dash instead. You can then change the line of code so it looks like this:

echo '<li><a href="/labels/'.$files[$key]['name'].'">'.ucwords(substr(str_replace('-',' ',$files[$key]['name']), 0, -5)).'</a></li> ';

You would think that Blogger would know better, why didn’t they just use dashes in the label file names to begin with, that is what they do with the blog post filenames.

13 thoughts on “Blogger Label List for FTP Published Blogs”

  1. Thanks!!!

    I’ve been looking for something like this for a while and couldn’t find it. I’m still convinced there must be a blogger template tag to do the trick otherwise why would nearly all the files in the blog be republished when the post has labels whereas just a few files are republished when the post doesn’t have labels?

    Anyway, thanks again… It meets my needs exactly…

  2. Jay,
    There should be a template tag to do this for those that FTP publish. If you ever find it please drop me a note. In the meantime, this does work and I am happy that you find it useful.

  3. Any solution on how to display the current label as the page’s h1 line if a page from the labels folder is displayed?

    thanks and best

  4. I have an idea of how it could be done using some PHP on a FTP published blog. I will give it a try tonight and make a post about it if I can get it to work.

  5. I attempted your solution but received the following errors. Warning: Division by zero in /usr/www/users/scrippy/palimpsest/index.html on line 529

    Warning: Division by zero in /usr/www/users/scrippy/palimpsest/index.html on line 529

    Warning: include_once(/usr/www/users/scrippyphp”) [function.include-once]: failed to open stream: No such file or directory in /usr/www/users/scrippy/palimpsest/index.html on line 529

    Warning: include_once() [function.include]: Failed opening ‘/usr/www/users/scrippyphp”’ for inclusion (include_path=’.:/usr/local/lib/php’) in /usr/www/users/scrippy/palimpsest/index.html on line 529

    I’m not a very experienced PHP user. Any hints on what I’m doing wrong?

  6. Thank you very much. It’s working now. I put together a few other code examples and managed to build a dynamically sizing tag cloud.

Leave a Reply

Your email address will not be published. Required fields are marked *