Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme »

Custom Field: Default Values


  #1  
Old Aug 22, 2009, 06:39 AM
gungo
 
31 posts · Jul 2009
San Juan, Puerto Rico
Custom Field: Default Values

I'm using a custom field to position a standard position image in my posts.

Not really knowing what I'm doing, I found an example somewhere and tried this:
custom field - image

I put this in the kicker area of the page/posts:
<img src="/wp-content/uploads/%meta('image')%" alt="%post-title%" />

This works fine as long as there is an image reference in the image field.
However, if the field is blank, I get an error plus an empty image box.

I can make this work by placing a blank .gif in the field every time I post something, but this will drive me crazy eventually.

Is there some php code that would insert the image if there is a value in the field, but leave the area blank (without error and image box) if there is no custom image field - or if the image field is blank?

If conditional code is not possible, would I be able to create a the field with a default value the same way that the meta fields are created when a new post is saved (I couldn't find where this was done).

I want to avoid anything that would be wiped out with theme upgrades.

Thanks!
  #2  
Old Aug 23, 2009, 01:02 PM
grasshopper
 
20 posts · Jun 2009
Hi gungo -

I too want a conditional call to display my custom fields (because they are taking over my posts when they are empty). I found a great tutorial at another site on Custom Fields and various conditional codes. The tutorial is at perishablepress.com

This was helpful, but my question is in what php document do I put this in? And, once I do, where do I format the output? Hopefully someone can help.

thanks
  #3  
Old Aug 23, 2009, 04:00 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Try replacing in functions/postinfo.php towards the top

// Callback function for post meta replacement
function meta_values($matches) {
$meta_key = $matches[1];
// "get_post_custom_values" returns an array. Turn it into a string, separated by commata
$meta_values = implode(", ", get_post_custom_values($meta_key));
return $meta_values;
}

with

// Callback function for post meta replacement
function meta_value($matches) {
global $post;
return get_post_meta($post->ID, $matches[1], true);
}
  #4  
Old Aug 24, 2009, 09:45 AM
grasshopper
 
20 posts · Jun 2009
thank you Flynn -

Gungo I hope this conversation is helping you...and i'm not hijacking your thread.

Flynn -

I entered the code as suggested and when I stripped out the codes in the Byline portion of the Post Info APO options, nothing came up.

I am using the custom fields to provide course schedule information. Please see the link as an example. http://www.grasshoppercloud.com/?page_id=15

I coded all of that scheduling detail into the APO options (post info items). But, some classes have 8 sessions, whereas others have only 1. So, I am trying to only show the session line if there actually is a session.

I looked at using get_post_custom, but I'm such a noob that I'm not sure what I'm doing, where to put the code and then where to format it as a table.

thanks for any help.
  #5  
Old Aug 24, 2009, 12:39 PM
grasshopper
 
20 posts · Jun 2009
Hi Flynn -

I figured part of it out.

I changed your above code to an "if" code as follows:

function meta_values($matches) {
global $post;
if (get_post_meta($post->ID, $matches[1], true)) :
echo "$matches[1]" . get_post_meta($post->ID, $matches[1], true);
endif;
}

Do you see if this will screw up anything else?

Now, I need to do two things:

(1) actually format the keys and data into a table and
(2) replace the custom "keys" with more user friendly Descriptors.

Can you help me with that?

thanks,

T
  #6  
Old Aug 27, 2009, 11:36 AM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
1) You can use HTML in the post info item text areas
2) I didn't understand this one

Bookmarks

Tags
custom fields

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Line breaks in post content field? sammie Atahualpa 3 Wordpress theme 4 Nov 12, 2010 04:04 PM
Styling the comments area title font, form field and label font, and form field sizes jkintzele Comments, trackbacks & pings 5 Nov 10, 2009 09:18 AM
[SOLVED] Display Custom Fields and Values Under Post Heading grasshopper Atahualpa 3 Wordpress theme 4 Jul 2, 2009 12:40 PM
Unlinking the file structure depedency for image directories in favor of DB values i.avi Atahualpa 3 Wordpress theme 1 May 21, 2009 05:02 PM
How to turn of the form/text field shadow? Fux Atahualpa 3 Wordpress theme 2 Apr 27, 2009 08:06 PM


All times are GMT -6. The time now is 09:07 AM.


Powered by vBulletin® Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.