Custom fields in wordpress

Author: admin
Publication date: November 24th, 2009
Category: How to

Custom fields in wordpress are important if you want to use custom functions in your theme or if you want to have a clean design. The implementation of custom fields is relatively easy.

Open your style.css file and paste the following code:

.leadpic {
float:left;
width:200px;
height:100px;
border:1px solid #bebebe;
padding:5px;
margin:10px 10px 10px 10px;
}

The code above can be customized as you want.

Now open the index.php file and search the following code:

<?php if (have_posts()) : while (have_posts()) : the_post

Under this code paste the following code:

<?php
$values = get_post_custom_values("Image");
if (isset($values[0])) {
?>
<div>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="" width="200px" height="100px" /></a>
</div>
<?php } ?>

To use this custom field you must add a new custom field from wordpress post options.

On the key field put image and on the value field put your image url.

The entire code from this article can be easily customized. For any questions feel free to post a comment.