It is no exaggeration to say that Charles Darwin revolutionized our understanding of nature and our place in it; I’ve cited a few articles that recognize his contributions in Linking Thinking. So, I’d like my personal blog to join the February 12 celebrations that will mark the 200th Anniversary of Charles Darwin’s birth and the 150th anniversary of his book, On the Origins of Species. In the geeky tradition of Google and Yahoo!, I’d like to dress my blog for Darwin Day with a custom logo.
My inspiration for the custom logo comes from a good-natured caricature of Darwin as an ape published in 1871, a time of growing acceptance of the theory of evolution. If an ape, why not a chihuahua? Afterall, Darwin believed there was a continuity among humans and all other species.
With logo in hand, I want it posted automatically. Since I’ll be kicking up my heals on Darwin Day, I won’t have time for any manual logo fiddling. Because I am learning PHP and have been mercilessly hacking the WordPress templates that run this site, my first thought was to use conditional tags, specifically the is_day function. Conditional tags let you display content based on the conditions you set. In this case, I want to display a special Darwin logo if the day is February 12. On all other days, I want to display the usual chihuahua logo. I was right about using conditional statements, but wrong about the function. The is_day function lets you control when a daily archive is being displayed; I want to control what content is displayed on a given day. Back to Google search for new tactics.
As is often the case in the World of WordPress, someone had already had the same brilliant idea, followed the same misguided path and someone else had already offered a better solution. On the WP-Hackers mailing list, Samuel Wood aka Otto of ottodestruct.com points out that the correct function to use is getdate, and he prescribes a concise bit of code that gets the job done. Here is how I adapted it for my needs:
<?php// Add special logos for special days$today = getdate();
// Darwin Day is Feb 12if($today['mon'] == 2 && $today['mday'] == 12){?>
<img src="<?phpbloginfo('url'); ?>/images/darwin-logo.png" alt="logo for Darwin Day" width="135" height="150" />
<p class="greetings">Happy Darwin Day. Celebrate science and reason on Charles Darwin's 200th birthday.</p>
<?php}// Christmas Day is Dec 25elseif($today['mon'] == 12 && $today['mday'] == 25){?>
<img src="<?phpbloginfo('url'); ?>/images/xmas-logo.png" alt="logo for Christmas Day" width="135" height="150" />
<p class="greetings">Merry Christmas. Peace on earth and good will to all.</p>
<?php}// default logo for all other dayselse{?>
<img src="<?phpbloginfo('url'); ?>/images/chihuahua-logo.png" alt="Portable Learner chihuahua" width="135" height="150" />
<p class="greetings">Getting there is half the fun.</p>
<?php}?>
This code displays special Darwin and Christmas logos on the home page on February 12 and December 25, respectively, and the regular chihuahua logo on all other days. Each time I want to recognize another significant day, I only need to add another elseif statement. Very nice, Otto.
Where does this bit of code go? Because I use the Thematic WordPress theme, I slipped this code between a pair of <li> tags in the widget-ready area called index-top asides. I also use a plugin that allows me to use PHP code in widgets, such as Sören Weber's Exec-PHP plugin.
If you aren’t using such a flexible theme, or do not want to use Sören’s plugin, then save this code as a PHP file, say logos.php. Then, call this file into the header.php:
<?phpinclude(TEMPLATEPATH . '/logos.php'); ?>
While my example focus on WordPress, this code can be used in any other PHP-driven content management systems such as Drupal and Moveabletype. Now, you can always have your blog celebrate with you.
Dress Up Your Blog for Darwin Day
Or any day for that matter. How to post special logos for special days with a little (very little) PHP. more →
My blog will be sporting a special logo for Darwin Day on February 12 only.
Tags
Charles Darwin, design ethos, WordPress
In This Series
Customize Your Blog
It is no exaggeration to say that Charles Darwin revolutionized our understanding of nature and our place in it; I’ve cited a few articles that recognize his contributions in Linking Thinking. So, I’d like my personal blog to join the February 12 celebrations that will mark the 200th Anniversary of Charles Darwin’s birth and the 150th anniversary of his book, On the Origins of Species. In the geeky tradition of Google and Yahoo!, I’d like to dress my blog for Darwin Day with a custom logo.
With logo in hand, I want it posted automatically. Since I’ll be kicking up my heals on Darwin Day, I won’t have time for any manual logo fiddling. Because I am learning PHP and have been mercilessly hacking the WordPress templates that run this site, my first thought was to use conditional tags, specifically the
is_dayfunction. Conditional tags let you display content based on the conditions you set. In this case, I want to display a special Darwin logo if the day is February 12. On all other days, I want to display the usual chihuahua logo. I was right about using conditional statements, but wrong about the function. Theis_dayfunction lets you control when a daily archive is being displayed; I want to control what content is displayed on a given day. Back to Google search for new tactics.As is often the case in the World of WordPress, someone had already had the same brilliant idea, followed the same misguided path and someone else had already offered a better solution. On the WP-Hackers mailing list, Samuel Wood aka Otto of ottodestruct.com points out that the correct function to use is
getdate, and he prescribes a concise bit of code that gets the job done. Here is how I adapted it for my needs:This code displays special Darwin and Christmas logos on the home page on February 12 and December 25, respectively, and the regular chihuahua logo on all other days. Each time I want to recognize another significant day, I only need to add another
elseifstatement. Very nice, Otto.Where does this bit of code go? Because I use the Thematic WordPress theme, I slipped this code between a pair of
<li> tags in the widget-ready area called index-top asides. I also use a plugin that allows me to use PHP code in widgets, such as Sören Weber's Exec-PHP plugin.If you aren’t using such a flexible theme, or do not want to use Sören’s plugin, then save this code as a PHP file, say
logos.php. Then, call this file into theheader.php:While my example focus on WordPress, this code can be used in any other PHP-driven content management systems such as Drupal and Moveabletype. Now, you can always have your blog celebrate with you.