Blogger, PHP, and Labels

I'm in the process of updating my Blogger template so that my new Blogger labels and their corresponding label pages have a reasonable user interface and are actually useful. My goals are to:
  • Make it clear when a label page is being displayed by including the label name in the page title and in any relevant headers & sidebar sections.
  • On the page for a label named label, display my bookmarks that are tagged with label on (and, of course, also display my blog items that are labeled with label).
The first step is to use PHP to get the label name into a variable, which I call $label. Here's how I do this:
$label = strtoupper(basename($_SERVER['PHP_SELF']));
if ($label == 'INDEX') {
$label = NULL;

// Note: This assumes no label will be named index

This sets the $label variable to the upper-cased label name if a label page is being displayed and to NULL if the top page (deflexiο is being displayed. Determining the label name is as simple as determining the page's filename (basename) because Blogger names each label page label.extension and I've set up my blog to use extensionless URLs.

Once the variable $label is set, I use code such as the following to unconditionally process statements:
echo "$label Deflexions (bookmarks)";
Note that this does the right thing on label pages and on the the top page (index). For example, on a label page this resolves to:
LABEL Deflexions (bookmarks)
And on the top page, this resolves to:
Deflexions (bookmarks)
To conditionally process statements, I use code like the following:
if ($label) {
echo "↓ deflexions & reflexions labeled $label";
Note that on the top page $label is NULL, which is considered FALSE, and statements inside the squiggly brackets will not be run.

I'm still updating my template so things are kind of a mess at the moment. I'm posting this now because I'd love to get feedback on my PHP code and my template. Please post your thoughts and tips as a comment to this blog item - thank you!

Labels: , , ,

Hashtag: #blogger-php- [?]

Post & Read Comments (located elsewhere)



Post & Read Comments (located here)

Post a Comment



Links to this page

Create a Link



Each item © Nancy McGough
Each comment © the author of the comment web site hosted by
deflexions powered by Delicious · reflexions powered by Blogger
More deflexions & reflexions, & feeds available via the sidebar top & bottom

[link] For bookmarks & links, please use this page's permalink [link]