Building simplicidade.org: notes, projects, and occasional rants

Upgraded individual article archive templates

I like to have the same sidebar on the right of my pages, both in the main page and in the individual article pages.

With MT, I always edited the templates to add the same sidebar on both the main index template and in the individual archive template.

Today, I tried something new. I added a new index template, sidebar.html, and copied the sidebar from the main index template. Then I removed that content from the main index template and replaced it with a include of the new template. Also I edited the individual article template in the archive section and added the same include there. You also have to change the class of the element to “layout-two-column-right”.

Now, my sidebar code is in a single template, for easy updating, and I can update a single template to change the sidebar on all the pages.

The include part is done in realtime using PHP. You can, of course, use whatever you want, but for simple include stuff, PHP is the best solution.

So, recap: to make certain elements of your blog layout easy to update (as in, having them in a single place), do this:

  • create a new index template with the common elements;
  • replace the places where they where being used with includes;
  • adjust css classes if needed.

For example, to make the main page sidebar appear on all the templates, do this:

  • from the main index template, take out the <div> with the “beta” class;
  • replace it with a <?php include "sidebar.html" ?>;
  • create a new sidebar template, and paste the original code there (make sure you check the “Rebuild this template automatically when rebuilding index templates”);
  • alter the individual article archive template, change the <body> element to the class “layout-two-column-right” and after the “alfa” <div, add something like <? php include("../../../sidebar.html") ?>. You have to adjust your path to the correct number of directories you crawl back, it depends on your archive URL layout.

Then make sure you setup Apache to filter all the HTML files via PHP. And then rebuild your entire site.