Aug 26

Most Desired WordPress Hacks: 11 Common Requests and Fixes

This is the first article in our new three-part WordPress series. I want to share with you some hacks that i found to be very useful when i was working on the redesign of Noupe and during the design of my other site Devsnippets. Throughout this article, we’ll be focus on many WordPress Theme hacks, ideas, tips and useful tutorials you need to have ready in hand when developing WordPress websites.

You might be interested to check out our previous four part series, "Powerful guide to master Your WordPress Theme

So let’s get started and don’t forget to subscribe to our RSS-Feed to keep track on our next post in this series.

Using Custom Fields to Display Post Thumbnails

Wp2-5 in Most Desired WordPress Hacks: 11 Common Requests and Fixes


One of the most interesting features in WordPress is using Custom Fields, which can turn your WordPress blog into a fully customizable CMS website. I use custom fields to create image thumbnail for each post here on Noupe and on Devsnippets as well and display the thumbnails on the home page and the Archive page.

Follow the steps below and you will get it ready

  1. You need to be able to upload images to your server in order to do this. You can do this using your FTP Client or any WordPress plugins to help you upload your images through the admin area.
  2. Open a new post and scroll all the way down to the bottom where it says Custom Fields. Click on the plus button to expand it.
  3. Enter the word “image_thumb” in the “key” field, and enter the fill path of the image that you uploaded in the “Value” field.
  4. Do what you usually do in every post: add title, post text, choose a category and publish.
  5. Now open your index.php file that is in your current theme folder, search for this line:
    <?php the_content('Read the rest of this entry &raquo;'); ?>
  6. Add the following code above that line
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
    <img src="<?php $values = get_post_custom_values("image_thumb"); echo $values[0]; ?>" alt="<?php the_title(); ?>" />
    </a>
    

Other great Solutions

Avoiding Duplicate Content

Duplicate content refers to two or more web pages that have the same, or almost the same, content. We must avoid duplicate content to not get penalized by search engines. But sometimes we need to show two (or more) lists of posts on one page, we usually do this by using Multiple Loops (one standard loop and one from a certain category). This is done when you want to feature not only the very latest post written, but also posts from a certain category.

<?php $my_query = new WP_Query('category_name=featured&showposts=1');
  while ($my_query->have_posts()) : $my_query->the_post();
  $do_not_duplicate = $post->ID;?>
    <!-- Do stuff... -->
  <?php endwhile; ?>
    <!-- Do other stuff... -->
  <?php if (have_posts()) : while (have_posts()) : the_post();
  if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
   <!-- Do stuff... -->
  <?php endwhile; endif; ?>

Other Solutions

Login Box in your sidebar

Wp2-2 in Most Desired WordPress Hacks: 11 Common Requests and Fixes


When i was designing DevSnippets, i wanted the users to easily login through the front page and skip the login page. Many solutions are out there and i found a good one at WPdesigner, i will add the code here just in case we don’t find it in the future.

                <li>
		<?php global $user_ID, $user_identity, $user_level ?>
		<?php if ( $user_ID ) : ?>
		<h2>Control panel</h2>
		<ul>
			<li>Identified as <strong><?php echo $user_identity ?></strong>.
			<ul>
				<li><a href="<?php bloginfo('url') ?>/wp-admin/">Dashboard</a></li>

				<?php if ( $user_level >= 1 ) : ?>
				<li><a href="<?php bloginfo('url') ?>/wp-admin/post-new.php">Write an article</a></li>
				<?php endif // $user_level >= 1 ?>

				<li><a href="<?php bloginfo('url') ?>/wp-admin/profile.php">Profile and personal options</a></li>
				<li><a href="<?php bloginfo('url') ?>/wp-login.php?action=logout&amp;redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']) ?>">Exit</a></li>
			</ul>
			</li>
		</ul>

		<?php elseif ( get_option('users_can_register') ) : ?>

		<h2>Identification</h2>
		<ul>
			<li>
			<form action="<?php bloginfo('url') ?>/wp-login.php" method="post">
				<p>
				<label for="log"><input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22" /> User</label><br />
				<label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
				<input type="submit" name="submit" value="Send" class="button" />
				<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
				</p>
				<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
			</form>
			</li>

			<li><a href="<?php bloginfo('url') ?>/wp-register.php">Register</a></li>
			<li><a href="<?php bloginfo('url') ?>/wp-login.php?action=lostpassword">Recover password</a></li>
		</ul>

		<?php endif // get_option('users_can_register') ?>

	</li>

Of course later i wanted to make it even more easier and prettier to register and login through the front page and skip the login and register pages, so we coded a small widget using Prototype to switch between the login and registration box all on the front page. I will write a tutorial about this very soon.

Creating a menu Showing Certain Categories

Topbar in Most Desired WordPress Hacks: 11 Common Requests and Fixes


If you would like to have a menu like the one we have here at noupe, to show certain categories, just add the line of code below and style it as you wish.

<ul class="topmenubar" style="float:left; width:720px;">
<?php wp_list_categories('orderby=name&include=7,72,23,16,1,7,17,26'); ?>
</ul>

The template tag, wp_list_categories, displays a list of Categories as links. You can Include or Exclude Categories as you wish, just enter the category id and don’t forget to add the “include” or the “exclude” parameters to manage it.

By default, wp_list_categories() generates nested unordered lists (ul) within a single list item (li) titled “Categories”. You can style that list item with a CSS selector.

Other great Solutions

  • Display categories in horizontal Drop-Down menu- This tutorial will explain how to create a horizontal menu bar showing the main categories and sub menus showing the sub-categories using CSS and javascript.
    Wp2-1 in Most Desired WordPress Hacks: 11 Common Requests and Fixes

  • Multi-level Navigation Plugin for WordPress- The plugin generates the code necessary to create a Son of Suckerfish horizontal dropdown, vertical flyout or horizontal slider menu. You have control over what items (pages, categories, archives, blogroll etc.) appear in your dropdown via the plugins options page.

Display Categories in a Dropdown box

Sometimes you want to displays a list of categories in a select (i.e dropdown) box with no submit button. The easiest way to do this is use the wp_dropdown_categories template tag.

<form action="<?php bloginfo('url'); ?>/" method="get">
    <?php
	  $select = wp_dropdown_categories('show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6');
	  $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
	  echo $select;
	?>
    <noscript><input type="submit" value="View" /></noscript>
</form>

Most Wanted Posts and Categories hacks

How to exclude certain categories from being displayed in the loop.

<?php if ( have_posts() ) : query_posts($query_string .'&cat=-13,-26'); while ( have_posts() ) : the_post(); ?>
  • Advanced Category Excluder- The main goal of this plugin is to enhance WordPress’s functionalities by hiding some unwanted categories, from defined parts of the blog like: your search results, your RSS feed listing, your category listing, and also your entry page, if you want to.

How to display posts from a certain category

If you want to display certain posts from a certain category like the one i am using for the news section on Devsnippets.

<ul  class="news">
     <?php query_posts('cat=6&showposts=5'); ?>
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Post Author Related Solutions

Having multiple authors on your blog is really fun, we need to have good solutions to have nice custom author pages, show their latest posts, highlight author Comments in WordPress posts, show their avatars and author bio below every post.

Getting Author Page on your WordPress blog

By default WordPress will use the author.php then the archive.php file then your index.php file to display the author info. That is, if you do not have an author.php file, WordPress will check for archive.php, and so on.

So, if you want to change the look of your author pages, you need to create an author.php file if it doesn’t exist, by copying archive.php if that file exists, or index.php if it doesn’t.

If you want to show the author’s main website, email contact, and biography, helping readers learn more about the author.

Articles by <?php the_author(); ?>
Author Website: <?php the_author_url(); ?>
Author Email: <?php the_author_email(); ?>
Author Bio: <?php the_author_description(); ?>

Solution

Display Author Bio below each Post

If you want to have that handy little author bio box at the top of the article with an author photo, you can do the following:

Wp2-4 in Most Desired WordPress Hacks: 11 Common Requests and Fixes


Solution

Separate Author comments from other comments

When you have multiple authors on your blog, you will need to style the author comments differently, here is how you can do it:

<li class="<?php if ($comment->comment_author_email == "authorname@domain.com") echo 'author'; else if ($comment->comment_author_email == "anotherauthorname@domain.com") echo 'author2'; else if ($comment->comment_author_email == "thirdauthorname@domain.com") echo 'author3'; else echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>">

Display Twitter Messages on your blog

If you want to display your Twitter status on your blog instead of using Twitter-hosted scripts to save loading time.

How to

  • Twitter Tools- Twitter Tools is a plugin that creates a complete integration between your WordPress blog and your Twitter account.
  • twitterRSS- This plugin allows you to pull in an rss feed from your twitter account and display it on your site.

143 Responses, Add Comment +

  1. Fubiz 26 August 2008

    Excellent tips !

  2. K-IntheHouse 26 August 2008

    Absolutely great tips. I am still trying to get my head wrapped around multiple WP queries. I am using it in a project at the moment but it just seems to break with any change I make elsewhere.

    Stumbled!

  3. spinach 26 August 2008

    OH?Good?I study some important things?I love this site?

  4. Lachy 26 August 2008

    Awesome, cheers! Got a few articles like that on my website :D

  5. JamieO 26 August 2008

    The multiple query thing is a great example. The other piece I would mention is to ensure you delete any page templates that you are intentionally not using in your design.

  6. The Floating frog 26 August 2008

    A great resource article, I’ll bookmark this for later!

  7. Billee D. 26 August 2008

    Awesome! Thank you so much for pooling these resources into one convenient place.

  8. Sheena 26 August 2008

    Great! Thanks for putting this together, its been a big help.

  9. Nick 26 August 2008

    Although I wouldn’t call them “hacks”, it’s a great post! Thanks!

  10. Noupe 26 August 2008

    Thank you all guys, i am glad you found some useful stuff here.

    @JamieO,
    I agree, you need to delete any unused template files due to the Template Hierarchy WordPress is built on, Which controls which template file(s) will WordPress use when it displays a certain type of page.
    Good point :)

  11. Chris 26 August 2008

    Thanks for the info. More and more clients are wanting a CMS solution and it’s great to be able to bring more flexibility to WordPress.

    On a side note… I like your site design and colours, but a little more spacing between your “fixes” would make it a lot easier to read.

    Cheers!

  12. hitman 26 August 2008

    EXCELLENT TIPS! GREAT!
    THANKS THANKS THANKS A LOT :)

  13. Mommy Brain Reports 26 August 2008

    Thanks for the tips!!! Definitely bookmarking this page!!! I need some new ideas for my site!

  14. Luke 26 August 2008

    Re: Avoiding Duplicate Content

    The code you have provided would only handle a single featured post. It would be better to use an Array to hold the displayed post IDs and then check against that, thereby allowing similar code to be used with multiple loops returning multiple posts.


    have_posts()) : $my_query->the_post();
    $shownPosts[] = $post->ID;?>


    ID , $shownPosts ) ) continue; update_post_caches($posts); ?>

  15. MikeWhoBikes 26 August 2008

    There are some terrific, useful tips here. Thanks for posting!

  16. Noupe 26 August 2008

    @Chris,
    Thanks for the feedback. I added more space now for every headline fix.

    @Luke, I agree with you. The code i provided here handles a single featured post. Thats why i provided a link to a nice solution by Weblog Tools Collection that shows how to avoid duplicating multiple posts.

  17. ???? 26 August 2008

    thanks for your tips,it’s very useful,great~~~

  18. JONxBLAZE 26 August 2008

    These are awesome hacks…thumbs up for sure!

  19. Adrian | Rubiqube 26 August 2008

    Wow! Great stuff! This is the kind of post I like most. The “inside info from the trenches” kind. ;) Keep them coming!

  20. Jason N. 26 August 2008

    You can also create a twitter account for a blog at http://www.mysidekick2.com and readers twit to each other…

  21. Splinter09 26 August 2008

    “Using Custom Fields to Display Post Thumbnails” exactly what I needed for my blog. And the other tips are just great, first time here but I’m sure to be coming back. Nice work.

  22. Nathan Beck 27 August 2008

    Yeh thanks a lot Noupe some top tips there!

  23. The Floating frog 27 August 2008

    Wordpress plugins interest me alot so thanks for the interesting post.

  24. d3bruts1d 27 August 2008

    Nice tips!

  25. James 27 August 2008

    Awesome tips! … Bookmarked! :)

  26. Max | Design Shard 27 August 2008

    This will be useful to me , thanks for posting

  27. IhateDesign 27 August 2008

    Great tips, a few one i want to use a long time ago..

  28. Steve 27 August 2008

    great Noura! I especially like the dropdown categories listing, something that I have been looking for. I think this can be used in the sidebar along with the archives dropdown, especially when space is limited.

    The exclude category code is also very useful when doing advanced WordPress templating I have found.

  29. Susan 27 August 2008

    Wow…this is very helpful. I’ve added it to my bookmarks!

  30. NaldzGraphics 27 August 2008

    very nice tips serve!!.thanks a lot.

    Ronald

  31. Firewalker 27 August 2008

    Just a suggestion for the list:
    Replacing Wordpress search with Custom Google Search without additional post or page:

    http://tinyurl.com/59tg5a

  32. Gerasimos 27 August 2008

    Excellent tips! It seems that Wordpress with so many plugins and tips laying around can work in any way we want.

  33. Marketing Network 28 August 2008

    Indeed great tips! Thanks for the time you spent writing this excellent post!

  34. Mihai 28 August 2008

    The new Noupe design rocks and allways good resources, thank you!

  35. Web Design Adelaide 28 August 2008

    Great post again. Some of these will come in handy.thanks

  36. pmtate 28 August 2008

    Great tips, one issue is your copy to clipboard piece on the code snippets corrupts the code, the view plain is a better option.

    copied as <?php should be <?php etc.

    Paul

  37. pmtate 28 August 2008

    That didn’t display as intended, the copy to clipboard converts the < into & lt ;

  38. Monika 28 August 2008

    Your tipps are great, but duplicate content doesn’t mean to show the same article on one page ;)

    duplicate content is: the same content under different URI.

    regards
    Monika

  39. Milan Petrovic 28 August 2008

    Great article, thanx.

    My Starscape theme has some of this ‘hacks’ built in and they can be controled through control panel settings. Theme has Post Author info, Related posts and Author archive page.

  40. byme 28 August 2008

    NIce tips
    byme

  41. Pinara.Net 28 August 2008

    Thank you for the hacks, i can make custom theme from this, bravo

  42. Mike 28 August 2008

    Great tips! Thanks as always…

  43. Jon 29 August 2008

    Excellent article, thanks very much

    The section on Avoiding Duplicate Content was especially useful for me, as this can be very tricky to get right with Wordpress

    Cheers, Jon

  44. Craig 29 August 2008

    Great tips, but small bug in “Display Categories in a Dropdown box”. When you select a category it displays the category pages, but the item in the form box goes back to displaying the very first category I selected.

    ?? any suggestions.

  45. Craig 29 August 2008

    Fixed … just delete &selected=6 from wp_dropdown_categories(’show_option_none=Select Category&show_count=1&orderby=name&echo=0′);

  46. Dror 29 August 2008

    Great ! keep on !
    Dror

  47. Jeromy 29 August 2008

    Another great post buddy!

    Thanks so much. I admit the language is a bit above my head (I am trying to teach myself how to do this stuff). But the info is GOLD.
    I am sharing your site as a Top Place for WordPress customization.

    Cheers,

    Jeromy

  48. Abhilash 30 August 2008

    An excellent resource! Found your site through Webtoolscollection. Will return here soon and check out your other content…
    Thanks!

  49. bangbouh 30 August 2008

    Great Tips. Thanks!

  50. webmaster blog 1 September 2008

    thnx

  51. cooper 1 September 2008

    I’d like to be able to do the category drop downmenu exclusion thing, with my links drop down, having a certain category of links displayed on the drop down front menu- excluding the rest.

  52. y5cafe 2 September 2008

    Great tip.
    Click [Thanks]. :)

  53. SarahG 2 September 2008

    For your highlighting of author comments you’d be better off comparing the ID and not the email. Two reasons
    1. If you change your email address your old comments will not match up to your profile’s new email address
    2. If you have a lot of authors on a multi author blog your if statement will get quite long.

    Comparing the ID is simple:

    if ($comment->user_id == get_the_author_ID())

    Providing the author is logged in (which they usually are), it will highlight the comment.

  54. Noupe 2 September 2008

    @Cooper,

    I’d like to be able to do the category drop downmenu exclusion thing, with my links drop down, having a certain category of links displayed on the drop down front menu- excluding the rest.

    If you want to exclude certain categories from the frop down box use the following code, ‘exclude=4,12′ means category IDs 4 and 12 will NOT be displayed.

    < ?php $select = wp_dropdown_categories('show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6&exclude=4,12'); $select = preg_replace("# ]*)>#", "

    @SarahG,

    For your highlighting of author comments you’d be better off comparing the ID and not the email.

    Good point SarahG, comparing ids is much better than emails. Thanks for the tip :)

  55. Icon 2 September 2008

    Excellent ! Great information, it’s time to customize my blog now. Thanks.

  56. Edi Susanto 4 September 2008

    Wow, those are great tricks for wordpress. About put category list into drop down, I want to put my tag list into drop down, how do i do that?

    Thanks

  57. zoel 5 September 2008

    Cools and must be try! ;-)

  58. Abdo 7 September 2008

    thanks a lot for sharing.

  59. blogsarticle 9 September 2008

    Although I wouldn’t call them “hacks”, it’s a great post! Thanks!

  60. Kudungga 11 September 2008

    Excelent thanks a lot for sharing.

  61. Frank Richard 16 September 2008

    Great tools/plugins, thanks for sharing, I will share the twitter scripts with my friends!

  62. moti levy 17 September 2008

    Thank you very much
    great tips i used some of them

  63. zmijata 6 October 2008

    Nice Work :)

  64. Fat Man 6 October 2008

    Great Post. I always noticed the custom fields but never really thought they had any significance to my work.

    It interesting the way you used them to include the thumbnails in the archives. It’s a nice touch.

    I will be experimenting with them now.

  65. hulif 6 October 2008

    It interesting the way you used them to include the thumbnails in the archives. It’s a nice touch.

    I will be experimenting with them now.

  66. wwrth 6 October 2008

    Great Post. I always noticed the custom fields but never really thought they had any significance to my work.

    It interesting the way you used them to include the thumbnails in the archives. It’s a nice touch

  67. ciscopower 9 October 2008

    Very good tips. I will try some of them in my website.
    Thanks.

  68. Jeff 20 October 2008

    Great tips…thanks!

  69. Yeca 29 October 2008

    Great job ! Thanks !

  70. mrgtb 3 November 2008

    great article, pity I don’t use wordpress. Well not really seeing as I use my own custom blog.

    But seriously, great site you have going here

  71. bugjee 16 November 2008

    Very good tips. I will try some of them in my website.

  72. office space 1 December 2008

    thanks for your tips,it’s very useful,great

  73. hj-cha 4 December 2008

    Great job ! Thanks !

  74. antiquarian books 10 December 2008

    Great site. Thanks… :)

  75. Xtence 15 November 2009

    Very usefull, thanks for sharing !

  76. Vijendra Mishra 2 January 2010

    Nice Hacks thanks for Login Solution.

  77. Web Design Adelaide 21 January 2010

    Another great post, thanks for the information!

Trackbacks

Leave a Reply

Comments are moderated – and rel="nofollow" is in use. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!