Custom Fields Insertion


Author Message
Marty

Posted: 10/31/2009
Quote message 

I have been learning about custom fields. I have spent a great deal of time on this feature and quite frankly it has been a frustration experience. After many hours of viewing many tutorials, I have gotten to the point where I can display a custom field. One thing I have not found information on is the placement of the field. I do not know the techinique of placing. In other words I want to place my field right below my main text in my content area. Does anyone know how I can do that? I hope someone can help me out, because this has just driven me nuts. I'm sure it's easy, but I'm just not getting it.

Thanks so much.
Marty
 
Marty

Posted: 11/1/2009
Quote message 

Can anyone help? Thanks.
 
Bud

Posted: 11/1/2009
Quote message 

Just wrap it in a DIV and give it a class...


<div class="custom-field">
You custom field code here
</div>


Then give it some CSS to style it the way you want.

Bud
budstechshed.com
 
Marty

Posted: 11/1/2009
Quote message 

thanks, Bud. Don't I have to put some php code in my page. A loop?
 
Bud

Posted: 11/1/2009
Quote message 

Here's an example of getting a custom field called "post-icon" and putting it in a DIV somewhere in the WP loop...


<div class="custom-field">
<?php echo get_post_meta($post->ID, 'post-icon', true); ?>
</div>


That would output whatever value is in the custom field. If it was a link to an icon image it would just output the URL.

To make it a little more useful you could do something like this...


<div class="custom-field">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> <img src="<?php echo get_post_meta($post->ID, 'post-icon', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" /> </a>
</div>


That would make it an actual image that links to the post.

So it depends on what you want to do with the custom field and then you need to wrap it up in some HTML and CSS to make it useful and styled to match your theme.

Bud
budstechshed.com
 
Marty

Posted: 11/2/2009
Quote message 

Thanks, Bud for taking the time to explain in such detail. I do appreciate it. I'll give this a whirl. You're a good man. :)
 

Reply


NAME *
EMAIL
SMILIES :-) :( :-D 8-) :*) :-/ :-{} :-X :-O :-@ O:) :-P :-< :-( :-| ;-) 
CODES [Quote] [B] [I] [U] [Code] [IMG] 
BODY *  
VALIDATION *