Wordpress Custom Fields and Hacks for Bloggers

You can use wordpress to create a custom and professional looking website. In this post we are sharing some wordpress custom field tricks and hacks that will allow you to have a better wordpress powered site.

Sometimes there could be guest bloggers who only writes one post  on your site and that’s all. You can use this method to show regular author information. Keep in the mind the author has be registered in wordpress. Maybe, you do not want to register every time a new guest authors writes. But, how do you still get guest author information to show up in the same format as regular author? Custom Fields !

Guest Author Name in the Front Page and Individual Posts

The first thing we need to do is to set a wordpress if statement to get the custom filed value. This way it will only show up when the custom file value is assigned. Open up your “index.php” and “single.php” and paste the following code where you want the author name to show up. It could be after date or after comments. For example after this code: <?php the_time(‘M j, Y’) ?>
01_author_name

< ?php if ( get_post_meta($post->ID, 'guest_author_name', true) ) { ?>
// check to see if custom field guest author name exists
< ?php echo get_post_meta($post->ID, "guest_author_name", $single = true); ?>
< ?php } ?>

Once we put the if statement we just call it on whichever post we want the guest author name to show up. The guest author name should show up on the front page and for specified post only.

02_autor_name_custom

Guest Author Information Block on Individual Post

Okay , so we have the name showing up in the in the post meta description but some information about the guest author would be nice too.
03_author_info
Again, first we have conditional if statement. which looks for author image thumb and description. Do not forget to change the image the directory. Also, we attached a class to the block and thumb, it allows to style both image and the block using CSS.

&lt;?php if ( get_post_meta($post-&gt;ID, 'autho_thumb', true) ) { ?&gt;
               //check to see if autho_thumb  custom field exist and gets the thumbnail
             &lt;div class=&quot;writer_bio&quot;&gt;
            &lt;img class=&quot;autho_thumb&quot; src=&quot;http://desizntech.info/wp-content/uploads/author/&lt;?php $values = get_post_custom_values(&quot;autho_thumb&quot;); echo $values[0]; ?&gt;&quot; alt=&quot;Author Thumb&quot; width=&quot;60&quot; width=&quot;60&quot; height=&quot;60&quot; /&gt;
&lt;?php } ?&gt;
               //check to see if description exist
&lt;?php if ( get_post_meta($post-&gt;ID, 'guest_author', true) ) { ?&gt;
&lt;?php echo get_post_meta($post-&gt;ID, &quot;guest_author&quot;, $single = true); ?&gt;&lt;/div&gt;
&lt;?php } ?&gt;

Here is the CSS I used

.writer_bio {
	color: #666;
	background: #eee;
	text-transform: none !important;
	font-size: 13px;
	font-weight: normal;
	height: 75px;
	width: 600px;
	padding: 6px;
	padding-bottom: 6px;
	padding-left: 0;
	margin-bottom: 10px;
}
.writer_bio img {
	padding: 0 !important;
	float: left !important;
	margin-left: 4px !important;
	margin-top: 3px !important;
	border: 2px #ccc solid !important;
	height: 60px;
}

You even style more with the class autho_thumb. Once that is done all you need to do it add the autho_thumb and guest_author in the field and fill out the information. You can even add HTML such as link in custom field.
04_author_descrption

So, there you have two custom field for guest author information. This might seems a lot of step. Trust me once have done it, it is just matter of adding the image and the description next time you want to do it.

Better Custom Field for Displaying Post Image on Front Page

post_thumb_ch

I saw this method on Smashing Magazine by Jean from Catswhocode. This method is used to display a thumb for the post on the front. Tutorial9 also did a similar tutorial. I wanted to take it a little bit further and make easy for the front end user. Also, with Jean’s method every the images would have  same alt=”post-image”  and I might not be good for search engine. Moreover, you would have to include the whole URL for images everytime. First here is the code:

&lt;?php $postimageurl = get_post_meta($post-&gt;ID, 'post-img', true);// variable for image
	    $image_alt = get_post_meta($post-&gt;ID, 'img_alt', true);// variable for description
// check if the the custom field is called
if ($postimageurl) {
?&gt;
      &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; rel=&quot;bookmark&quot;&gt;
&lt;img src=&quot;&lt;?php echo get_option( 'siteurl' ) . '/wp-content/uploads/thumb/' ?&gt;&lt;?php echo $postimageurl; ?&gt;&quot; class=&quot;post-img&quot; alt=&quot;&lt;?php echo $image_alt; ?&gt;&quot; width=&quot;500&quot; height=&quot;300&quot; /&gt;&lt;/a&gt;
&lt;?php } else { ?&gt;

Before I explain the code, notice that I did not add a else statement for a default thumb. Look at Jean’s post if you would like to have a default image if so image is assigned in custom field.

First we have two varibales $postimageurl and $image_alt. First one is to get image location and second one is to add the image name. Then again we set a if statement to check if the custom field gets called. The different thing is this code <?php echo get_option( ’siteurl’ ) . ‘/wp-content/uploads/thumb/’ ?> that gets the image location. I have create a folder called  thumb in my wordpress upload directory, so rather than typing the whole  URL evertime I would just type the image name, once I uploaded the image in the folder. Look at the following screenshot:

05_thumbail

If you want a different directory such as lets say you would store your images in the root of your domain just replace <?php echo get_option( ’siteurl’ ) . ‘/wp-content/uploads/thumb/’ ?><?php echo $postimageurl; ?> with http://yourwebsite.com/images/<?php echo $postimageurl; ?>.
So, the code is a little tweaked so every post image would have a different alt (title) and you would type the image name extension rather then whole URL.

Arrange Your Wordpress Navigation However You Want

The first thing to know is wordpress list pages using wp_list_pages tag, which is usually located in header.php. but you may not want  to list all your pages. If you want to hide all some of your pages from showing up you would do this:

  &lt;?php wp_list_pages('include=7,13' ); ?&gt;;
//or
&lt;?php wp_list_pages('exclude=5,9');?&gt;;

Exclude or include almost works the same way. Exclude will omit certain pages from wordpress page list and include only show the pages ID you specify. (How do I find my page id?). However, most of the web design blog or any other blogs like to use tags or categories as their navigation. In that case, you can just get rid of wp_list tag and custom code the navigation. For example: in Desizn Tech’s CSS categories is linked this http://desizntech.info/category/css/ .  Alternately you can do that with your tags as well. The benefit of coding this way you can assign CSS class to style each element of the navigation.

Showing Archive Topic

Most of the wordpress themes comes with  archive.php  page . But, I have seen many websites where the archive pages is not very helpful  and does not tell users what topic or categories they are browsing. You can add the following codes in your archive.php to avoid that confusion.

06_wordpress_archive

&lt; ?php /* If this is a category archive */ if (is_category()) { ?&gt;
		&lt;h3 class=&quot;pagetitle&quot;&gt;Current Browsing Topic: &amp;#8216;&lt; ?php single_cat_title(); ?&gt;&amp;#8217;&lt;/h3&gt;
 	  &lt; ?php /* If this is a tag archive */ } elseif( is_tag() ) { ?&gt;
		&lt;h3 class=&quot;pagetitle&quot;&gt;Posts Tagged  as &amp;#8216;&lt; ?php single_tag_title(); ?&gt;&amp;#8217;&lt;/h3&gt;

Snazzy Archive and Clean Archives Reloaded are two cool plugins that improves wordpress archive page.

That’s it for now. If there any cool wordpress trick or hack you know please share with us.

If you enjoyed this post, get free updates by email or RSS.

Posted Under: Wordpress

Tagged: , ,

  • Bookmark on Delicous
  • Share on Reddit
  • Share on Technorati
  • Share on Facebook
  • Share on Stumble Upon
  • Share on Stumble Upon

35 Responses to “Wordpress Custom Fields and Hacks for Bloggers”

  1. Chris says:

    Thanks for the author hacks! I’ve been looking everywhere for something like this, and no one had a really decent post on it for some reason. You rock!
    Chris´s last blog : 27 Astrologers Interviewed at NORWAC 2009

  2. Johnson Koh says:

    Great list! Am looking forward to more!

  3. Bunker says:

    Interesting and informative. But will you write about this one more?

  4. Tanay says:

    Great Post! This is very helpful.
    Tanay´s last blog : The Ultimate WordPress SEO Checklist

  5. Thanks for the awesom useful tips. “Custom Field” is really powerful for optimizing your WP posts.

  6. Jakes says:

    Great post bro

  7. Elena says:

    I recently came across your blog and have been reading along. I thought I would leave my first comment. Nice post!

  8. Phoenixheart says:

    Thanks for the useful tips. “Custom Field” is so powerful and extensible a technique, but overusing may cause the code and post to look fragmented IMO.
    Phoenixheart´s last blog : How I sped up my Thica.net

  9. Anchorage says:

    Stupendous! White Hat Hacking.. Love it

  10. the get_post_meta if conditional is a life changer!

    I mean i knew about get_post_meta, just never thought about the if then. Great stuff.

  11. Very helpful. I will be using the post-img custom fields in my new Wordpress blog. Thanks!

  12. John says:

    Great blog, thanks for the post…..I check the blog daily!Johnhttp://www.spectramindz.com

  13. Hermitbiker says:

    Great post DesiznTech…. trippy little tricks, codes and hacks for making a better built WordPress blog… thanks for the tips and for creating your blog !!

  14. Pixzii says:

    Some themes that you like don’t support image thumb on homepage. That hack tutorial for image thumbs is really helpful. Thanks :)
    Pixzii´s last blog : 16 Cute Wood Sculptures by Yuri Firsanov

  15. Enk. says:

    nice list.. really useful hacks there ! :)

  16. Very Helpful hacks. I have used almost all of them. Thanks.
    Bariski | TutZone.net´s last blog : 22 Firefox Extensions (Addons) for Web Development

Trackbacks/Pingbacks

  1. WordPress Hacks | webmaster.lk | English ::
  2. 22 Latest Exceptional WordPress Hacks | EzTips | Wordpress Tips - Tutorials - Make Money Online
  3. 22 Latest Exceptional WordPress Hacks | Programming Blog
  4. 10 WordPress Hack Links and Articles Nov 2, 2009 | Technical Dig
  5. Wordpress Custom Fields and Hacks for Bloggers « Wordpress Plugins
  6. BrainBoom 44.09 | Sharebrain »
  7. All Teched Up! « Caintech.co.uk
  8. links for 2009-10-29 | Digital Rehab
  9. Wordpress Custom Fields and Hacks for Bloggers « Netcrema – creme de la social news via digg + delicious + stumpleupon + reddit
  10. Wordpress Custom Fields and Hacks for Bloggers | Host1Plus.com
  11. CSS Brigit | Wordpress Custom Fields and Hacks for Bloggers
  12. Wordpress Custom Fields and Hacks for Bloggers
  13. WPUK » Wordpress Custom Fields and Hacks for Bloggers
  14. {GoGoGo} » Blog Archive » Wordpress Custom Fields and Hacks for Bloggers
  15. Tweets that mention Wordpress Custom Fields and Hacks for Bloggers -- Topsy.com
  16. Wordpress Custom Fields and Hacks for Bloggers
  17. Wordpress Custom Fields and Hacks for Bloggers WP Air
  18. uberVU - social comments

Leave a Reply

Premium webmaster graphics - Brushes, Vectors, Icons, PSD layouts
Hosted By
SecureSignup.net