Taking WordPress to the Next Level
Looking for an amazing yet affordable theme for your site? Join Elegant Themes for the all-inclusive price of $39, and you're only paying 50 cents per theme!
Our host today is Sampath Amitash. If you're interested in getting in front of the readers of Site Sketch 101, check out our guest posting invitation here.
WordPress is by far, the most flexible blogging engine available in the world (wide web). In fact, I personally consider that WordPress has been under-rated as a mere blogging engine. I feel it is more or less, a CMS or at least it can be modified to function like a CMS. In this post, I will teach you some ways that can take WordPress to the next level.
Use Multiple Loops on the Homepage
In order to get the reader stick to your blog, you must get that professionalism right on your homepage because it is the homepage that will reflect your entire blog and content. You can customize your homepage to look more professional by using multiple WordPress Loops to show posts based on various criteria. For example, on My Blog (Amitash.com), you can see that I have listed out posts form one category as featured posts on the top. Below that I listed 4 posts from another category, and then the reviews and guides follow.
I was able to show posts from specific categories on the homepage in separate sections using multiple loops, whereas by default, most WordPress themes come with a single loop. Let me show you how to create a loop of posts for a separate category. Such loops can be many on a particular page.
First, find the main loop in your WordPress theme Index.php file, it will look something like:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!– All Post Styling and info (like titles, excerpts) would be here!
–>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<?php endif; ?>
Between the main loop, you can add custom loops to get posts from a particular category or with a specific tag or posts that match certain custom fields. Let’s see how to do it.
I added the following code in between the main loop to get 3 posts from category 140 (This is the category ID). Obviously, you can enter any category ID and any number of posts to get.
<?php $recent = new WP_Query(“cat=140&showposts=3″);
>have_posts()) : $recent->the_post();?>
<!– Custom Loop Styling –>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
Just like the above custom query, you can add many but all must be within the main loop. If you look at my blog again, then you will also notice that I used separate divs for each section and customized them and you can add the following code to apply separate styling for specified categories.
<?php if (is_category(array(142,146,167,168,169,181,189))) {?>
<div class=”special”>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php } elseif (is_category(array(145,148,199))) { ?>
<div class=”superspecial”>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php } else { ?>
<div class=”normal”>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php } ?>
Therefore, we can specialize some category’s display. Note that the numbers displayed are Category IDs.
Although category styling can be done in 2 ways, unfortunately for tags, there is only one possible way and that is using the if-else-elseif statements. To do this, first you must have a tag.php file in your theme’s root folder. For example:
<?php if (has_tag(array(‘sharp’,'mild’,'extreme’))) {?>
<div class=”specialtags”>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php } elseif…
And the code continues just like in the categories.
For custom search results page, you must have a search.php file in your theme’s root folder.
Use Custom Fields Professionally
If you see on my blog’s homepage, I have a Software Reviews section and a How-To section. These sections, I have created using the multiple loops trick I explained earlier. But you can see that they have additional data like review stars, watch video button etc. If you are wondering how I achieved this and what a lot of coding I did, then you might be mistaken because this trick requires minimal hard-coding into your theme files.
Have you heard of WordPress Custom Fields? With Custom Fields, these extra data can be easily inserted anywhere in your theme within the loop. For example, in my blog, I add videos to the How-to section using custom fields. When there is an empty custom field value, a “No Video” button appears. I first added a “Video” Custom Field Key with a YouTube Video URL as a value. Then I added the following code to the How-To Custom query in my theme’s index.php.
<?php
$video = get_post_meta($post->ID, ‘Video’, true);
if ($video == ”)
{ ?>
<a href=”#” class=”video”>No Video</a>
<?php } else { ?>
<a target=”_blank” href=”http://www.youtube.com/v/<?php echo $video; ?
>&showsearch=0&rel=0&hd=1&fs=1&ap=%2526fmt%3D18″
class=”button”>Watch Video</a>
<?php } ?>
Similarly, you can use custom fields in any way. I also used this technique to add review starts alongside my Software reviews. The extent to which custom fields can be used is limited by your imagination only. Thank you for reading this article. If you have any difficulty with any aspect of the tutorial, then ask it in the comment box below or look into WordPress Codex for detailed information. There are few more ways of taking WordPress to the next level that I will cover in the next article.

Craig Carrigan said:
This is definitely going on my saved bookmarks list of great WordPress info. I love seeing people get the most out of WordPress and feel that it’s a great platform for a TON of different things, including websites, blogs, etc… Thanks!
Amitash said:
@Craig, In the beginning, even I underrated WordPress and in the process tried out various other systems but finally I got to know its flexibility and came back to it. Now I can think of WordPress for any kind of website that comes in my mind!
Christopher Masiello said:
Sampath,
This is a great tip. I have something like this set up on my homepage. I have a few feature sections that pull in articles from key categories.
Thanks,
Chris
Sampath Amitash said:
Nice Blog there Cris, I could see that you different section of posts from various categories.
Brankica @ Live Your Love said:
Seems like really easy thing to do. I can’t seem to collect the courage to do stuff like this. I am just sure I would mess up the code.
Fortunately I managed to install a local WP on my lap top so I am hoping I can test all this there.
Thanks for all the codes.
I am wondering if all this depends on the theme we are using?
And what is your theme, I am guessing you made it yourself?
Thanks
Brankica @ Live Your Love recently posted..Twiends- part 2 How to maximize ROI with this Twitter tool
Sampath Amitash said:
Brankica, It is quite easy to implement these codes and it doesn’t depend on the theme. You can set these up on any theme as they contain core WP functions.
I modified the Glow Theme (From ElegantThemes) and using it on Amitash.com.
Just like you rightly said, you must either backup your installation or try it on localhost before injecting any new code, no matter how small it is.
Dana said:
So, this how you do it. I have visit your blog and like what I see. I bet your bounce rate is quite low with that design.
Dana recently posted..Cell Phone Screen Protector- Screen Protection and More
Sampath Amitash said:
@Dana, My blog is still very new and yes the bounce rate is decreasing substantially.
I have to admit that I feel surprised because everyone seem to like the design but I am yet to hear comments for the content in it. LOL
JamestheJust on Elance said:
Sampath –
NICE. In two paragraphs I was in tears wondering who gave me the right to run a blog…
Ugh! I am no coder, no geek – you’re amazing.
Thanks for the incredible post..and showing me how much I have yet to learn.
Can you mail me your brain?
JamestheJust on Elance recently posted..Passive Income for November 2010
Amitash said:
@James, I am overwhelmed by your comments. Thanks a lot.
The fact is I am no coder myself but I was able to learn so much on WordPress thanks to Nick and many other pro bloggers and the WordPress codex.
I feel the codex is a cool place to find new tricks for WordPress and then bloggers like Nick and comments like yours just add to the inspiration.
Ana | Traffic Generation Cafe said:
Wow, I had no idea half of these characters existed.
Great post, Amitash; looks like even I could do it. Will take some convincing though…
Ana Hoffman
Ana | Traffic Generation Cafe recently posted..Bloggers- If You’re Not Struggling- You’re Failing
Dennis Edell @ Direct Sales Marketing said:
While I won’t personally touch it, this will be immediately emailed to my design partner; awesome stuff!
Dennis Edell @ Direct Sales Marketing recently posted..Contest Prize Sponsors Wanted for Upcoming Comment Contests!
Dean Saliba said:
I love WordPress, it is just so customisable. I reckon there is nothing you could not make it do.
I also like finding new little customisations to make my blog look better.
Sampath Amitash said:
We all love WordPress. I like to try making different types of websites with WordPress.
Ryan said:
You make a great point. If you visit a wordpress theme website such themeforest dot net, you’ll notice they offer themes for a variety of websites other than blogs. The versatility of wordpress extends into virtually any type of site.
Thanks for the coding tips. I already understand how to code wordpress, but I appreciate the idea keeping visitors on your site longer with the use of custom loops.
Ryan recently posted..Do I Need a Bartending License to Get a Bartending Job
Kok Siong said:
This is a great guide for the WordPress user especially for me as a new user. Thanks for the details guideline. However, there are more things to be explored in WordPress.
Kok Siong recently posted..Renal Carcinoma Survival Rate Statistics
Dexter Gregory said:
Wow this is a great share. But I still need to harness my artistic side but the code would be very useful for starter. Thanks.
Dexter Gregory recently posted..Smallville Season 10 Episode 11 – Icarus
Sampath Amitash said:
Glad that the code would be useful as a starter. Thank you!
Kevin said:
I’m a big wordpress fan…As soon as I get my blog running smoothly, I’m hitting the books and learn as much as I can about WordPress.
Good Post!
Kevin recently posted..How To Install Thesis Theme On WordPress
Sampath Amitash said:
I suggest you go through the codex first. It is an excellent repository for starters as well as pros.
Nate Lawliet said:
This was great! The Codes will surely help a lot

Nate Lawliet recently posted..The New Villain in Transformers 3- Dark of the Moon- Shockwave
Amitash said:
Glad that it was of help!
Reza Winandar said:
Well, thanks for the tutorial dude! WP is a real blog engine while another is already taking up too
Reza Winandar recently posted..5 Types of Comments That Attract Attention
Pete said:
I really, really like the ease of wordpress but really do not have the skills to do this sort of stuff. Maybe I should learn because the amount of money people charge for simple tweaks like the one you show above is unbelievable!
Pete recently posted..Television Beds
Thomas said:
Hi Sampath
That is some great tips I will try out later. I have been doing some php coding back in time so I think those example should be easy for me to follow. Thanks for sharing.
Thomas recently posted..Enable Autologin on Windows 7 and lock the screen