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 ' · '; } ?><?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.
· <a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php echo htmlentities(the_title()); ?>">Del.icio.us</a> · <a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?t=<?php echo htmlentities(the_title()); ?>&u=<?php the_permalink() ?>">YahooMyWeb</a> · <a href="http://www.spurl.net/spurl.php?url=<?php the_permalink() ?>&title=<?php echo htmlentities(the_title()); ?>">Spurl</a> · <a href="http://www.furl.net/storeIt.jsp?url=<?php the_permalink() ?>&title=<?php echo htmlentities(the_title()); ?>">Furl</a> · <a href="http://www.technorati.com/search/<?php the_permalink() ?>">Incoming links</a>


16 responses so far ↓
Ziru // May 7, 2006 at 10:17 pm
I’ve try showing google adsense 2 blocks on 1 page, but just one showed. Confused
How to edit Wordpress themes using Dreamweaver at Leon Kilat ::: The Cybercafe Experiments // Jun 7, 2006 at 3:37 am
[...] To tweak your WordPress theme even further, you might want to check my repository of pieces of great WordPress theme codes, feel free to suggest snippets that should be added there. I still have to finish the second part of my article: How to create a WordPress theme: A guide for the design-challenged non-geek. I’m thinking of finishing part 2 by next week (fingers crossed). Posted by Max Limpag Filed in Blogs, Highlights, Blog design [...]
A fire, a map, and a WordPress theme at Leon Kilat ::: The Cybercafe Experiments // Jul 26, 2006 at 4:20 am
[...] Brighthouse is a theme for the Typo blogging platform. I spotted it when checking out features of SlimTimer. I really like the theme, it reminds me of the design of the Signal vs. Noise blog. I converted it for WordPress over the weekend, using the bits of code I collected in this blog post. [...]
Announcing Brighthouse-WP theme for WordPress at Leon Kilat ::: The Cybercafe Experiments // Jul 28, 2006 at 2:49 am
[...] I created the theme using the pieces of WordPress code I collected in this post: blog titles optimized for search engines, social bookmarking links after the post, better “more” link etc. I’ve found a few great snippets of code that should be added to that post. [...]
DeStructUred Blog » Blog Archive » links for 2006-09-04 // Sep 9, 2006 at 4:44 am
[...] Pieces of WordPress theme code: a repository at Leon Kilat ::: The Cybercafe Experiments Repository of code for WordPress Theme design (tags: WordPress Design Blog Theme) [...]
bongobelly.com » Blog Archive » Customizing Wordpress Themes // Oct 4, 2006 at 6:10 am
[...] I found some useful stuff here, gotta give it a plug. http://max.limpag.com/2006/04/08/pieces-of-wordpress-theme-code-a-repository/ [...]
How to convert any web template into a WordPress theme | Leon Kilat ::: The Cybercafe Experiments // Oct 12, 2006 at 2:43 am
[...] You can simplify the template conversion by keeping as reference a copy of a working WordPress theme. You can just then copy snippets of code from the theme for use in your own template. You might also want to check these pieces of great WordPress theme code that I’ve collected. [...]
Convert HTML to Wordpress Theme part 1 · Techbites on Discombo // Mar 17, 2007 at 10:55 pm
[...] http://automattic.com/code/widgets/themes/pieces-of-wordpress-theme-code-a-repositoryhow-to-edit-wordpress-design-using-dreamweaver/http://codex.wordpress.org [...]
Jürgen // Mar 18, 2007 at 5:47 am
Great Post. Very Helpfull information. Thanls, guys. Jürgen from Germany
AK // Dec 20, 2007 at 2:17 pm
~
Hey there.,
Have any idea how many WordPress sites that I searched to try to figure out how to add a simple URL Click to my WP banner image?!?! Even the guy who DESIGNED the theme did not have this info on his page.,
I only just installed WP this evening and am hacking it as I type this., all I can say is Boy do I miss being able to edit in Dreamweaver., what the heck are people thinking with this WP stuff., what a learning curve.
Now it seems that I have to learn PHP, CSS and MySQL, all of which I have avoided for many years., oh well., time to burn my eyes out on the screen even more now.,
THANKS for making this one piece of my job a little easier., will be checking out more of your site soon.,
AK
~
Max Limpag // Dec 22, 2007 at 3:22 am
AK,
You can edit themes with Dreamweaver. I wrote about it in this blog: http://max.limpag.com/2006/06/07/how-to-edit-wordpress-design-using-dreamweaver/
Cheers!
AK // Dec 24, 2007 at 1:28 am
~
Hi Max;
Yeeesh., yes., thanks., I saw that post., but I wonder., which is more time consuming and hair pulling., doing as you suggest and diss-assembling and then re-assembling the various code bits., or just going to the various files and editing there?!?!
This all seems so archaic in the year 2007., who the heck would “design” a system (hah., some system) where the design code for one site is in ten different files and NOT viewable or editable in ONE system or piece of SW at one time?!?
One can only hope that we will look back on this time of “design” and say,. goodness., glad that we are way past that mess! It just seems a bit overly convoluted to me., yes?
AK
~
Max Limpag // Dec 25, 2007 at 2:28 pm
AK,
If you want just a single file to control your design, you can choose not to break it up. Include the code for headers, sidebars and footers in index.php. The breaking up of the files allows you to re-use code (i.e. header, sidebar, footer) for different sections of your WP blog: index, post entry, page, archive etc.
5 wordpress php code snippets | Pingable :: Blogging and Social Media // Apr 11, 2008 at 3:52 pm
[...] Make Your WordPress Header Image Clickable [...]
5 Wordpress PHP Code Snippets | prowordpress.org | WordPress News, Plugins and Themes Download Guide.. // Aug 18, 2008 at 6:48 am
[...] Make Your WordPress Header Image Clickable [...]
Pieces of WordPress theme code: a repository | Squico // Jul 6, 2009 at 11:00 pm
[...] In: WordPress themes 6 Jul 2009 Go to Source [...]
Leave a Comment