Conditional content on your WordPress blog

On the old version of WEBBAGE, I showed a different image depending on what type of page you’re on.  For example when reading a blog article or the blog homepage, you’d see a circle image to the left saying “the BLOG”.  That’s because this page is in the blog. If you go to the LAB or the MAN sections of the site, you’d see the image change.

How do you show different content depending on what page you’re on?

Using some really basic php that you can get from the WordPress site and then amending it slightly for your needs.  This is the code I used on the site

<?php if (is_category('the LAB')) { ?>
<a href="/the-lab"><img src="/wp-content/themes/twentyten/images/the-lab.png" height="210" width="210" alt="the LAB logo"></a>
<?php } elseif (is_page('the MAN')) { ?>
<a href="/the-man"><img src="/wp-content/themes/twentyten/images/the-man.png" height="210" width="210" alt="the MAN logo"></a>
<?php } else { ?>
<a href="/the-blog"><img src="/wp-content/themes/twentyten/images/the-blog.png" height="210" width="210" alt="the BLOG logo"></a>
<?php } ?>

What this is saying is, “if this page is in the LAB category, show the LAB image link. If not, check if this page is the MAN page and if it is, show the MAN image link. If it’s not either of these, show the BLOG image link”.

I do a similar thing now with the top navigation by highlighting the section you’re reading in pink.

Simples!

Part of CODE. Bookmark the permalink.

Leave a Reply