Get the Right Copyright Dates in Your Blog Footer

A tip for self-hosted WordPress users.

Contrary to popular belief, most blogs are copyrighted. As a result, most blog themes include a copyright notice in the footer.

How the copyright notice is entered into the theme determines how it appears:

  • If entered as plain text, it appears as a static date or range of dates — whatever you entered. This means that each new year — right about now — you need to change the static text to include the current year.
  • If entered using tags that pull the most recent date’s year from your WordPress blog — or just use the current year — a range of dates may not appear at all. Instead, there will be just one date. That’s better, but not exactly accurate.
  • If entered using PHP tags that get the first and last years of blog posts and put them in a range — you never have to modify the footer to change the dates and they always include the entire range of post years. This is the best solution and it isn’t difficult to do.

To automatically display a range of dates from the year of your first post to your most recent post in a copyright notice, just edit the code in the footer to remove your current copyright notice code and replace it with this:

< ?php global $wpdb; $post_datetimes = $wpdb->get_results("SELECT YEAR(post_date_gmt) AS year FROM $wpdb->posts WHERE post_date_gmt > 1970 ORDER BY post_date_gmt ASC");
$firstpost_year = $post_datetimes[0]->year;
$lastpost_year = $post_datetimes[count($post_datetimes)-1]->year;

$copyright = __('Copyright © ') . $firstpost_year;
if($firstpost_year != $lastpost_year) {
$copyright .= '-'. $lastpost_year;

echo $copyright;
< ?php bloginfo('name'); ?>

The result, on this blog, would be something like:

Copyright © 2004-2009 Maria's Guides

If you prefer to have your name appear instead of the name of your blog, replace the last line with your name. That’s what I do.

Lynda.comLearn More

Learn more about working with a self-hosted WordPress 2.7 installation — or Check out my WordPress courses on

Video Blogging with Viddler and WordPress, Part IV

Displaying a list of your recent Viddler videos in your WordPress blog.

If you start using Viddler regularly — either to create video blog entries as discussed in the previous article of this series or to simply get video content online — you might want to make those videos accessible from within your WordPress blog. Fortunately, there’s a WordPress plugin that makes this very easy: viddlerRSS.

The ViddlerRSS plugin works like most other WordPress plugins. Drop it in your plugins folder and activate it. (You can learn more about how to do that in our WordPress book, so don’t expect to find details here.) Then open your WordPress dashboard and choose Options > viddlerRSS. Enter your Username in the appropriate box, select the number of videos to display and, if desired, enter the HTML code you want before and after each video thumbnail. Then click Update viddlerRSS.

viddlerRSS Options

Now roll up your sleeves and open the template file where you want to insert the Viddler video thumbnails. (Need help modifying theme files? You can learn about that to do that in our WordPress book, too.) In most cases, this will be your sidebar.php template. Insert the following code into the file where you want the thumbnails to appear: < ?php get_viddlerrss(); ?>

Or you can get fancy like I did and put some intelligence into it, in case you ever need to disable the viddlerRSS plugin. Here’s the code I use, which includes a heading and other formatting settings:

< ?php if (function_exists('get_viddlerrss')) { ?>

  • My Latest Viddler Videos

    < ?php get_viddlerrss(); ?>

  • < ?php } ?>

    Save the changes to your template file.

    My Viddler VideosNow check your blog to see the results of your efforts. As shown here, I’ve got viddlerRSS set up to display thumbnails for my most recent three videos in my blog’s sidebar. Pointing to a video’s thumbnail displays the title of the video, which can help people decide whether they want to view it. Clicking a thumbnail image opens the video on the Viddler site.

    Easy enough, right?

    The next (and last) article in this series will explain how you can include a video commenting feature in your WordPress blog. Stay tuned!

    How to Display Category-Specific Introductory Content

    Another WordPress how-to.

    The other day I got an e-mail message from a site visitor that was full of complements about my site. He especially liked the fact that different introductory content appeared for my Book Support categories. For example, if he was looking at the category for our WordPress book, he’d see the book cover and information about that book, as well as links related to that book. But if he looked at the category for my Mac OS book, he’d see information related to that title.

    Two Category Archive PagesHow, he wanted to know, did I do that?

    With conditional statements in my WordPress template files.

    Why Bother?

    First, let me take a moment to talk about why you might want to go through the trouble of customizing category archive pages.

    In my case, my Web site combines information of interest to readers of my books (ie., book support) with my personal WebLog. Since some visitors come solely for book support, I needed to make them feel as if they’d reached their desired destination when they clicked a book support category link. I also had to assure them that they’d reached the pages for the specific book they’d come for.

    This required two kinds of custom information:

    • A welcome message that explained the kind of information they could expect to get. I decided to put this information in the body of the page, right beneath the category heading.
    • Book specific information directly related to what they were promised in the book in the way of support, including links, downloadable files, etc. I put this in the sidebar, with book cover images to make it clear which book they were getting support for.

    How could you use this on your site? Well, suppose your blog covers a variety of very different topics and you want to provide information for each topic on its category archive pages. Or suppose you’re using WordPress as a CMS and want to use categories for different product lines; you could have product line-specific content on each category archive page.

    It Isn’t Difficult to Do…But it isn’t Exactly Easy, Either

    Setting up different category information is as easy as inserting conditional statements in your WordPress template files with category specific information included.

    WordPress 2 (Visual QuickStart Guide)Of course, if you’re not familiar with rolling up your sleeves to insert that code, it might not be easy for you. That’s why Miraz and I wrote our WordPress book. To explain things like that. And that’s why I won’t repeat what’s in that book here. (Sorry!)

    With that said, here’s my code with an explanation of what it does and how it works. If you know how to modify your WordPress template files, you should have no trouble customizing this to meet your needs and inserting it on the proper places in your template files to get the same results.

    In the Page Body

    My site’s theme, a heavily modified version of Exquisite, includes a category.php file. This is the template that’s used whenever someone requests a category archive page by clicking a link to a category (as opposed to a single entry or date).

    If your theme does not include a category.php file, it probably includes some code in an archive.php file or even the index.php file to specify what should appear on category archive pages. That’s what you should zero in on because that’s where this first bit of code needs to be inserted.

    (Frankly, it’s a lot easier if you have a separate category.php page, so why not consider whipping one up? It’s great practice!)

    < ?php if (is_paged() ) { ?>

    < ?php } else { ?>
    < ?php if ( is_category('24') || is_category('25') || is_category('26') || is_category('27') || is_category('28') || is_category('29') || is_category('30') || is_category('31') || is_category('32') ) { ?>
    < ?php include (TEMPLATEPATH . '/langerbooksintro.php'); ?>
    < ?php } ?>
    < ?php } ?>

    Let’s take it in sections.

    < ?php if (is_paged() ) { ?>

    This determines whether the visitor is viewing something other than the first page of the category archive. If he is, all this stuff is skipped. I didn’t want the intro to appear at the top of every page for the category — just the first page.

    < ?php } else { ?>
    < ?php if ( is_category('24') || is_category('25') || is_category('26') || is_category('27') || is_category('28') || is_category('29') || is_category('30') || is_category('31') || is_category('32') ) { ?>

    This says that if it isn’t paged (in other words, it is the first category page), which category is it? Is it one of the ones listed here by number?

    < ?php include (TEMPLATEPATH . '/langerbooksintro.php'); ?>

    Well, if it is one of those, then display the contents of the file containing the intro (langerbooksintro.php). That’s a separate PHP file I created in the same directory to hold the book support introductory text. I like to keep my template files neat and this was my solution. I could also have replaced this statement with the information I wanted to appear on that first category page.

    < ?php } ?>

    This closes up that second IF statement.

    < ?php } ?>

    And this closes up the first one.

    Pretty simple, no?

    One thing to remember: the category archive page heading is outside all this conditional stuff. It’s set to display the category name and description as you see formatted in the illustration above. It’s like that on every page of my site.

    In the Sidebar

    I did pretty much the same thing for the sidebar, but I had to break it down into individual categories. Here’s my code:

    < ?php if (is_home()) { ?>

    < ?php } elseif ( is_category('24') ) { ?>

    < ?php include (TEMPLATEPATH . '/macosvqs.php'); ?>
    < ?php } elseif ( is_category('25') ) { ?>

    < ?php include (TEMPLATEPATH . '/excelvqpj.php'); ?>
    < ?php } elseif ( is_category('26') ) { ?>

    < ?php include (TEMPLATEPATH . '/excelvqs.php'); ?>
    < ?php } elseif ( is_category('27') ) { ?>

    < ?php include (TEMPLATEPATH . '/quickbooksvqs.php'); ?>
    < ?php } elseif ( is_category('29') ) { ?>

    < ?php include (TEMPLATEPATH . '/wordvqpj.php'); ?>
    < ?php } elseif ( is_category('30') ) { ?>

    < ?php include (TEMPLATEPATH . '/wordvqs.php'); ?>
    < ?php } elseif ( is_category('31') ) { ?>

    < ?php include (TEMPLATEPATH . '/wordpressvqs.php'); ?>
    < ?php } elseif ( is_category('32') ) { ?>

    < ?php include (TEMPLATEPATH . '/oopbooks.php'); ?>
    < ?php } else { ?>

    < ?php } ?>

    Again, let’s take it in sections.

    < ?php if (is_home()) { ?>

    This starts a section I set aside for announcements I might want to appear at the top of the sidebar on the Home page. I commented it out because I’m not currently using it.

    < ?php } elseif ( is_category('24') ) { ?>

    < ?php include (TEMPLATEPATH . '/macosvqs.php'); ?>

    If it’s not the home page, then is it the category page for category 24? If so, I want to insert specific content for that category. I do that by calling a separate file with that information in it. (This helps keep my sidebar.php file small.

    I do this for a bunch of book support categories, one after the other. Each one calls a separate file with content I can modify at any time to update book covers, titles, etc.

    < ?php } else { ?>

    Here’s where I start to wind up the if statement stuff. I created a catch-all area for all pages that don’t meet the previous criteria — either the home page or one of several specific categories. If I wanted to include sidebar content for those pages, I’d put them after this. I don’t, so there’s nothing here. But I’m prepared!

    < ?php } ?>

    And finally, this is where I close the conditional statements. Everything after this appears for all pages.


    You can use these basic constructions your your WordPress theme files to display different content for different categories or types of pages. It’s the same basic formulas, so to speak, with different ingredients. Doing this makes it possible to completely customize your pages based on content.

    Try it for yourself! Just remember to keep backup copies of all of your modified theme files — just in case you mess up and need to start over again.

    Good luck!

    How to List Random Posts in a WordPress Blog’s Sidebar

    Draw people into your blog by showing them other posts in the same category.

    People browse blogs all kinds of ways. One way is to come in at the Home page and browse what’s there, then click a category link in your navigation bar to go deeper into the site. Clicking a category link identifies a topic that interests them. But how can you get them to keep browsing what’s there when all they’ll see is the few most recent posts displayed there?

    imageOne way is to display a random list of category posts in the sidebar (see screenshot right or visit this page for an example). There are a number of ways to do this, but the quickest and easiest (which is usually my preferred method) is to use the Customizable Post Listings plugin by Scott Reilly with a few simple lines of code inserted in your sidebar.

    Customizable Post Listings isn’t new. Its latest version (1.1) was released back in 2004. But it still works like a charm — at least in WordPress 2.0.4 on my server. From the description:

    Display Recent Posts, Recently Commented Posts, Recently Modified Posts, Random Posts, and other post listings using the post information of your choosing in an easily customizable manner. You can narrow post searches by specifying categories and/or authors, among other things.

    I already use it on to display recent posts and recently commented posts, so adding another feature that takes advantage of this plugin wasn’t a big deal. In fact, it made sense.

    I won’t go into details about how to download and install the plugin. You can figure that out for yourself. If you’re new to WordPress and plugins and need help, I will plug the book I co-authored with Miraz Jordan here: WordPress 2: Visual QuickStart Guide. It has a whole chapter dedicated to plugins. Enough said.

    Once the plugin has been installed and activated, open your sidebar.php file (or the file in which you want to include the random post code). Then enter the following code where you want the list of random posts to appear:

    < ?php if (is_category()) { ?>

    < ?php single_cat_title('Random Articles in '); ?>

      < ?php c2c_get_random_posts(16,"
    • %post_URL%
    • ", $wp_query->query_vars['cat']); ?>

    < ?php } ?>

    Keep in mind that this code uses the tags I use in my sidebar for formatting: h2 for sidebar headings and ul for an unordered list. Your HTML formatting may differ, so you might have to adjust this a bit for your site.

    The first and last lines of this code provide conditional instructions. They basically say that if the page being displayed is a category page, show the random posts listing. So if the Home page or a single post page is displayed, the random category list does not appear.

    The single_cat_title tag is a neat way to customize the heading so it displays the name of the category.

    You might also want to change the value in the c2c_get_random_posts tag. I have it set to show 16 posts; you can show more or fewer. If you put a value in there that’s higher than the number of posts in the category, all of the posts will be displayed in random order. But if you want to display all of the posts, why not do it in reverse chronological order? Just replace

    < ?php c2c_get_random_posts(16,"

  • %post_URL%
  • ", $wp_query->query_vars['cat']); ?>


    < ?php c2c_get_recent_posts(150,"

  • %post_URL%
  • ", $wp_query->query_vars['cat']); ?>

    Remember to make the value big enough to cover all the posts in each category. I don’t know if there’s a limit to the value, but I probably wouldn’t use this if I had more than a hundred or so posts in a category anyway. It would make the sidebar too long. (My opinion.)

    Of course, you might want to change the heading, too — something like

    < ?php single_cat_title('All Articles in '); ?>

    would be more appropriate when showing all the posts.

    As you can imagine, there are lots of ways you can play with this to list post titles in the sidebar. And if your post titles are intriguing enough, these few lines of code might keep visitors on your site a bit longer.

    Watch that Theme

    Are there hidden ads in your WordPress theme?

    Just Shelly has posted an interesting article about how some WordPress themes incorporate advertising links. If those links are not removed when you modify the theme for your own use, you’ll be including ads on your site that you’re not getting compensated for! And those ads aren’t necessarily for products/services/sites that you want to promote on your site.

    Read more here: