Categories
Blog design Open source

Pieces of WordPress theme code: a repository

Share

The great thing about open source is that you can build on what others have done. In my quest to port an open source web design into a WordPress theme, I’ve used bits and pieces of WordPress theme code that have served me well in previous designs.

I am posting these pieces of code here so that this post will serve as the repository in case I need to customize another theme. Please feel free to suggest additional code bits so that I can add it here. Just post it in the comment field and enclose it in code tags.

SEO friendly title

I got this from K2, what this does is place the title of your post before your blog name. The conditional tags take out the at, which connects the post title to your blog name when you�re, for example, in the home page. You don�t want your home page title to start with at.
<title><?php wp_title(''); ?> <?php if ( !(is_404()) && (is_single()) or (is_page()) or (is_archive()) ) { ?> at <?php } ?> <?php bloginfo('name'); ?></title>

Here’s another implementation as posted in the Dech blog.
<title>< ?php wp_title(' '); ?>< ?php if(wp_title(' ', false)) { echo ' &middot; '; } ?><?php bloginfo('name'); ?></title>

Make header image clickable

This is a tip I got from K2 to make the header image clickable. Replace the starting div tag for the header with this:
<div id="header" onclick="location.href='http://max.limpag.com/';" style="cursor: pointer;">

Optimal ad display

This will place your ad block inside your first blog post. AdSense’s heatmap shows the area within the content to be an optimal area for the display of ads. I found this solution in the WordPress forum.

Place:
<?php $showAdSense = True; ?>
before the line:
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
Then insert this into the part where you want the ad to appear.
<?If ($showAdSense) { ?><div style="float:right;padding:3px;"> Ad sense code here </div><?php $showAdSense = False;} ?>

I usually insert it below the blog post headline and before the template tag that calls the blog post (the_content).

Better more link

Some templates still use just More to link to the full article. To replace this with Continue reading “title of the blog post.”

Replace the_content with
<?php the_content("Continue reading '" . the_title('', '', false) . "'"); ?>

Social bookmarking of posts

This will add links for the bookmarking of your posts in del.icio.us, Spurl and Furl as well as track incoming links from Technorati. The Sociable WordPress plugin automates this but I prefer doing it using template tags. I should update the link because I spotted one site that will allow you to submit to all these social bookmarking services.
&#183; <a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php echo htmlentities(the_title()); ?>">Del.icio.us</a> &#183; <a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?t=<?php echo htmlentities(the_title()); ?>&u=<?php the_permalink() ?>">YahooMyWeb</a> &#183; <a href="http://www.spurl.net/spurl.php?url=<?php the_permalink() ?>&title=<?php echo htmlentities(the_title()); ?>">Spurl</a> &#183; <a href="http://www.furl.net/storeIt.jsp?url=<?php the_permalink() ?>&title=<?php echo htmlentities(the_title()); ?>">Furl</a> &#183; <a href="http://www.technorati.com/search/<?php the_permalink() ?>">Incoming links</a>

Share

By Max Limpag

Max is a journalist and blogger based in Cebu City, Philippines. He is co-founder of the journalism start-up InnoPub Media.