Custom Fields


December 30th, 2009 By WidgetReadyThemes

customCustom Fields is a very powerful feature in wordpress as it push your limits to do anything you want with you site , i’m going to illustrate some practical use for custom keys and will include some real world examples .
Custom Fields around us in every blog we visit everyday , we can find it in the use of posts’ thumbnails , post sponsors or even in post’s advertising .

Custom keys consists of two fields (key and value)

Key : the unique key you use to define and call that custom key
Value : the value of that key , may be text , image code , video code or anything you want .
ex :
key : mode
value : happy
ex:
key : thumbnail
value : image.jpg

How to use

custom-keys

How to call the custom key

You’ve defined you custom key and value within your posts or pages, now how to show these values within the post or page
Here’s the php code that calls a certain custom key value
<?php $values = get_post_custom_values("KEY"); echo $values[0]; ?>
the KEY is you custom key , for example #1 above , it’ll be mode . The above code will call the custom key , get it’s value and prints it
for example #2 above it’ll be like that as it’ll be getting an image
<img src="<?php $values = get_post_custom_values("KEY"); echo $values[0]; ?>" alt="" />
this will get the custom key (thumbnail) value which will be image , inserts it in the image html code and shows it .

too simple , right ?

Here’s an usage example for custom keys from our blog
custom-key2
As you see custom keys opens alot of new options’ channels so get creative .

Comments are closed.