10 WordPress Hacks to Make your Life even Easier

Published On November 3, 2008
128 Comments Leave a Comment

The last post that I had made on 10 WordPress Hacks to Make your Life Easy got a good number of comments and views. Based on the success, I have decided to make another WordPress Hacks post to make your life EVEN easier. Here is the list of 10 new hacks ready to be bookmarked :-

How to make a Sticky Post

A sticky post is one that will always be on top of all your recent posts and stay there until you change it. You can use a sticky post as a notification, reminder or something that you want to emphasize to your readers. Here is how you can make a sticky post :-

First, decide on a category name that will hold all your sticky posts. For example, you can create a new category and name it “Stickies” and later use this name to call the posts from this category. Now, if you have ever opened the index.php file in any blog styled WordPress theme (Just install the basic Whiteboard theme for this tutorial), you will notice that it has a loop which is used to call your posts.

The loop begins here :-



and this loop should end here :-


Sorry, nothing matches that criteria.


Copy everything from the start to the end of this loop (including the above code). Paste it above the existing loop so that index.php will have two identical loops, one over the another. To make the sticky post appear, we will use this new loop which will call a single post from the “Stickies” category.

In the top loop, just replace this code :-



with this :-




have_posts()) : $my_query1->the_post(); ?>

So, if you decide to change the category name from “Stickies” to something else, just change it in the above code. You can also change the number of posts that you want to show from the sticky category by modifying the showposts variable.

Breaking Categories into Columns

Normally when the list of categories is displayed in the sidebar or on any part of the theme, it displays in a single column. Through the following hack, you can split your categories’ list evenly into two or more columns which can save space and not make your pages longer. Usually in WordPress, the following code is used to call the categories’ list (you can find it in one of the sidebar files) :-



Now, we will try and split the categories into two columns. Replace the above code with the following :-


",wp_list_categories('title_li=&echo=0&depth=1&style=none'));
$cat_n = count($cats) - 1;
for ($i=0;$i<$cat_n;$i++): if ($i<$cat_n/2): $cat_left = $cat_left.'

  • '.$cats[$i].'
  • ';
    elseif ($i>=$cat_n/2):
    $cat_right = $cat_right.'

  • '.$cats[$i].'
  • ';
    endif;
    endfor;
    ?>

    Basically the above code will split your categories and put them into two lists (left and right). Now all you have to do is style them so that they float left of each other. Add this code to your style.css file :-


    .right {float:left; width:140px;}
    .left {float:left; width:140px;}

    You might have to make some cosmetic adjustments in the above code so do it at your own pace.

    Making Unobtrusive Tabs

    If you have been following the latest trend of Premium WordPress themes, you will notice that special tabs are used (mostly in the sidebar part) to display different content like recent posts, comments, archives etc. When you click on any tab, only the content under that particular tab gets highlighted and the rest of the tabs’ content stays hidden. This allows the blog owner to display more content in less space.

    Download this file :- Domtabs

    Extract the domtab.js and domtab.css files from the archive and place it in your theme folder. Now add the following code in your header.php file above the tag :-



    In order to show the tabs, add the following code anywhere in the template. Try adding it to the sidebars :-

    Insert contents of the first tab here,
    e.g. The code for a plugin.

    Insert contents of the second tab here.

    Insert contents of the third tab here.

    You can change the content for the tabs by altering the code within the paragraph tags and edit domtab.css file for styling information.

    Listing Blog Authors

    If you are running a multi-user blog and want to list authors, here is the code to do it.

    Here is what the parameters do :-

    exclude_admin: 0 (include the admin’s name in the authors) / 1 (exclude the admin’s name from the list)
    optioncount : 0 (No post count against the author’s name) / 1 (display post count against the author’s name)
    show_fullname : 0 (display first name only) / 1 (display full name of the author)
    hide_empty : 0 (display authors with no posts) / 1 (display authors who have one or more posts)

    Displaying Categories in a Drop Down Menu

    First, add the following code to any part of your theme to show the category list. The recommended choice will be your header.php file which contains the navigation. You can add this code where the navigation ends :-



    Download this file :- Category Menu and extract both catmenu.css and catmenu.js files to your theme folder. Now, add the following lines to your header.php file before the tag :-



    Finally replace



    with



    To see the category drop-down menu in action, make sure you have categories and sub-categories set up on your blog. Also make sure that they have some posts in them.

    Displaying Google Ads in only first 3 posts

    Many bloggers want to display Google Ads in their first three posts only (since Google Adsense only allows 3 strips in a page) but have a hard time doing so without the help of plugins. Let me tell you how to integrate it efficiently into your WordPress theme. Open up your index.php file and look for the loop.

    The loop begins here (it can differ for your theme so look for the part that displays your blog posts) :-



    and this loop should end like this :-


    Sorry, nothing matches that criteria.


    Ideally, your Google Adsense code should be placed between the start and the end of this loop. So, just pick a position (after the title or at the end of the content) and place the following code :-


    current_post < 3) { ?>


    Just replace the commented line with your adsense code, save this file and check your theme. It should display three units of adsense code in your first 3 posts just like you always wanted.

    Displaying Recent Comments

    In order to display your most recent comments, you will have to modify your functions.php file from the theme folder. If the functions.php file is not present, make a new text file, name it functions.php and add it to your theme folder. Add the following code to it and save the file :-


    ', $post_HTML='

    ') {
    global $wpdb;
    $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,
    SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC
    LIMIT $src_count";
    $comments = $wpdb->get_results($sql);
    $output = $pre_HTML;
    foreach ($comments as $comment) {
    $output .= "

  • ID) . "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."...
  • ";
    }
    $output .= $post_HTML;
    echo $output;
    }
    ?>

    Now, wherever in the theme you want to display the list of recent comments, just add this code :-



    Highlighting Author Comments

    It takes a bit of tweaking to separate the author’s comments from the readers’ comments. Usually it can be done by changing the color or style of the author’s comments. Here is how can go about doing the same :-

    Open up the comments.php file from your theme folder and try to locate the following piece of code :-

  • id="comment-">

    Replace the above code with this :-

  • "

    Finally, add this to your style.css file in the theme folder :-


    .authorstyle {
    background-color: #B3FFCC !important;
    }

    If you are the author and have made comments on a post, check it out. Your comments will have a different background color from the readers’ comments.

    Adding a Social Bar to your Posts

    Social bookmarking is important if you want your posts to reach more and more readers. Most of the times you have to hunt for a good plugin that will show little icons for different bookmarking websites under each of your posts that will help your readers to bookmark them. But it can also be done through code like this :-

    Open the single.php file from your theme folder. Copy the following code and paste it within the WordPress loop (preferably after the content) that calls your post :-

    Now, copy the following code to your style.css file for the theme :-


    .socials {font-size:10px; font-weight:bold; margin-bottom:10px; background-color:#FFFFFF; border:1px solid #BBB9B2; padding:5px 5px 5px 10px; width:540px;}
    .socials a {margin-right:10px; color:#BFBCB3;}
    .btn_email {background:url(images/mail.gif) left no-repeat; padding-left:15px;}
    .btn_comment {background:url(images/comments.gif) left no-repeat; padding-left:15px;}
    .btn_delicious {background:url(images/delicious.gif) left no-repeat; padding-left:15px;}
    .btn_digg {background:url(images/digg.gif) left no-repeat; padding-left:15px;}
    .btn_reddit {background:url(images/reddit.gif) left no-repeat; padding-left:15px;}
    .btn_technorati {background:url(images/technorati.gif) left no-repeat; padding-left:15px;}
    .btn_furl {background:url(images/furl.gif) left no-repeat; padding-left:15px;}

    Finally, download this zip file that contains the icon images for all the social bookmarking websites and place them in the images folder of your theme. Social Bar done 🙂

    Creating an Archives Page for your Blog

    You can create a Page Template for the archives page on your blog. Here is how to go about it :-

    Create a new file called archives.php and add the following lines to it :-



    The above code will give a name (Archive Page) to the template which you will see when making a new page in WordPress. Now add the following code to display a list of all your posts :-




    Finally, add this code to display categories and monthly archives :-


    Categories

    Monthly Archives


    Save the archives.php file and place it in your theme folder. Now, create a new page and name it anything you want. Just make sure that you choose the “Archive Page” template as the template for your new page.

    I hope that you liked this exhaustive collection of WordPress hacks and also hoping that it will help you in some way 🙂

  • 128 replies on “10 WordPress Hacks to Make your Life even Easier”

    I got a call from some friends of mine the other day.
    While it is the traditional adornment for a bar, a mirror can date what should be an exciting,
    hip place to hang around. A few great art retail
    websites now have images available in bespoke wallpaper murals formats which mean that decorating had never been easier.

    Excellent post. Keep posting such kind of information on your site.
    Im really impressed by it.
    Hi there, You have performed a fantastic job. I will definitely digg it and for my
    part suggest to my friends. I am confident they will be benefited from
    this web site.

    Admiring the persistence you put into your blog and detailed information you provide.
    It’s nice to come across a blog every once in a while that isn’t the same out of date rehashed material.
    Wonderful read! I’ve saved your site and I’m including your RSS feeds to my Google account.

    I’m extremely impressed with your writing abilities and
    also with the structure on your blog. Is this a paid
    topic or did you customize it your self? Anyway stay up the nice quality writing, it’s rare
    to peer a nice weblog like this one today..

    What’s Going down i’m new to this, I stumbled upon this I’ve discovered It
    absolutely useful and it has helped me out loads.
    I am hoping to contribute & help other users like its helped me.

    Great job.

    Today, I went to the beach front with my children. I found a sea shell and gave it
    to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and
    screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I
    had to tell someone!

    Hello! I could have sworn I’ve been to this website before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be bookmarking and checking back frequently!

    can you please let me know that how did you set that social buttons at the end of the post where we roll over the icon and it stands up and comes out is there any plugin than please please let me know about it

    thanks,

    i just import the blog from old domain to new one.

    i try your code for category columns on seperate page () but nothing is displayed.

    whats is wrong with my blog or code, any guide pleas?

    Mad Chemist Reply

    Jai,
    These are extremely useful and cool hacks!!! Thanks for sharing these in your blog.
    For the last few days, I have been trying to generate at least 3 category/sub-category columns using code from “Breaking Categories into Columns”. As part of the description, you mentioned “Through the following hack, you can split your categories’ list evenly into two or more columns which can save space and not make your pages longer.” I have not been successful in generating more than 2 columns and don’t know how to change the code to display more columns. Could you please let me know how to change the code to accomplish this task? Thank you in advance for your help in this matter; it is greatly appreciated!

    I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work Look forward to reading more from you in the future.

    Such a great post. I’ve been wondering how to get categories into 2 columns forever. Quick question –

    How can you list categories in 2 columns AND show post counts? Can you guys post the code tweak? That would be amazing.

    “…. and also hoping that it will help you in some way”

    Thats purely an understatement. These tips have given me what I had been craving for all these days.

    Thanks for taking time and writing this up.

    All the hacks are essential for a WordPress blog. I was looking for a hack to split categories into two columns and I found it here… Thanks for it 🙂

    Hi good day,

    I have followed your tip in creating archives. But it didn’t work out. Care to help me?

    Please check my site, so that you’ll understand what i mean. Click on my monthly archives and see what does it do.

    Please help me. Please

    the archive template page was exactly what i was looking for. displaying display_category_as_images on that page will give me a great looking landing page. thanks!

    dear all,
    this is what i was trying to look for some times, and finally found it…. however i couldnt find the ”php wp list categories(); ” in my blogger html codes, so can u please tell me if there’s any alternative solutions to split the list of links we have?
    best regards

    dear all,
    this is what i was trying to look for some times, and finally found it…. however i couldnt find the ”” in my blogger html codes, so can u please tell me if there’s any alternative solutions to split the list of links we have?
    best regards

    dear all,
    this is what i was trying to look for some times, and finally found it…. however i couldnt find the ”
    ” in my blogger html codes, so can u please tell me if there’s any alternative solutions to split the list of links we have?
    best regards

    Tony Reply

    I don’t know where this stuff goes? Open what? a template? what if it is a free tempate? how do I open it? Dreamweaver? do I cut/paste this code into the page? at what point?

    I’m new to this and can’t find a clear set of instruction on how to use any of this code. Where do you people learn this stuff?

    Help!!!!

    Hey! I just don’t get it. My platform is wp, I have not upgraded cuz I don´t have credits, I seem unable to make changes to the style sheet. Also I can´t edit css so I guess what I’m trying to ask here is if I can actually change anything from my template without actually upgrading?

    thanks lovely

    Can’t Stop to post Comment for Your Valuable Work……..

    i m Recently shifted from blogger to wordpress…..

    And This Post is a Boom for me

    Thanks

    Now i m gonna check your rest of post too 🙂

    Instead of using the Sticky note.. you can also use the shantz-wp-prefix-suffix plugin “which allows you to add any text and/or HTML/CSS code to your posts and/or pages as prefix and/or suffix. (That includes even any new or old posts and pages and even your feed)”
    http://wordpress.org/extend/plugins/shantz-wp-prefix-suffix/installation/

    I use that plugin together with my Adsense Manager plugin. 🙂 = Awesomeness!
    http://www.mutube.com/mu/getting-started-with-adsense-manager-3x/

    I can see that even if I am not really much of a techie guy with wordpress hacks that you are indeed enjoying what you are doing.

    My brother will like this because I know that he likes hacks a lot especially if it is WP coz he even had multiple templates designed for him just to have it under his name. I’m gonna give it a shot to let him know. Thanks, Bob….

    Leave a Reply

    Your email address will not be published. Required fields are marked *