Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

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
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
  #7  
Old Aug 30, 2009, 02:55 PM
grasshopper
 
20 posts · Jun 2009
Hi Flynn -

Thanks for getting back to me. I think there is some problem (inconsistency) between the conditional call for custom meta values and when they are "printed"

I added the conditional call to only get the values if they exist 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;

This code does bring back the values into the top of the post byline area.

But, I created tables in the Post Info Item APO options to organize those values. These are now not being filled in. A sample of the HTML I am using is as follows:

<table class = "organization">
<tr>
<td width="15%">ORGANIZATION: </td>
<td width="35%"> %meta('organization')% </td>
<td width="20%">FEE:</td>
<td width="30%"> %meta('fee')% </td>
</tr>


Is the problem that the conditional values aren't being called into the tables because I am using $matches[1] in the conditional code and %meta% format in the tables? or in the print or preg_replace_callback function?

Thanks so much, I really appreciate any help.
  #8  
Old Aug 31, 2009, 10:31 AM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Try with

if (get_post_meta($post->ID, $matches[1], true) != '')
  #9  
Old Aug 31, 2009, 12:25 PM
grasshopper
 
20 posts · Jun 2009
Thank you Flynn -

I changed that line, but nothing happened. the custom fields are still showing up in the top of the byline area and not in the tables.

Any other suggestions?

Thanks so much.
  #10  
Old Aug 31, 2009, 07:04 PM
gungo
 
31 posts · Jul 2009
San Juan, Puerto Rico
Thanks for the suggestions... will report back when I try them out...
  #11  
Old Sep 1, 2009, 04:28 AM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Quote:
Originally Posted by grasshopper
Thank you Flynn -

I changed that line, but nothing happened. the custom fields are still showing up in the top of the byline area and not in the tables.

Any other suggestions?

Thanks so much.
So you're trying to display them twice? It's possible that they only work once per page. Try using them only once per page. (And I guess you closed the table with </table>, and did just not include that in your post here)
  #12  
Old Sep 11, 2009, 10:37 AM
grasshopper
 
20 posts · Jun 2009
Flynn -

A million apologies for this very late reply. I normally get those email notifications, but must have missed this one.

I'm hoping you can still help me.

I only want to display the custom fields once in the tables I created within the post info items in the byline area. And, I only want them to show up when there is an actual value assigned, so I did the conditional code in the php document. The conditional calls are showing up outside of the tables.

How do I get the conditional "calls" for the custom fields to populate the tables that I created in the post/info items ATO options?

oh and yes, I am finishing with the </table>, I just sent you a small snippet.

Thanks so much Flynn.
  #13  
Old Sep 11, 2009, 06:38 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Are you using Atahualpa 3.4.2, the most current version?

Try using this code right in the post info item text area (instead of editing functions/postinfo.php)

PHP Code:
<table class = "organization">
<tr>
<td width="15%">ORGANIZATION: </td>
<td width="35%"> <?php $post_id $post->ID
$meta_value get_post_meta($post_id'organization'TRUE); 
if (
$meta_value != '') echo $meta_value?> </td>
<td width="20%">FEE:</td>
<td width="30%"> <?php $meta_value get_post_meta($post_id'fee'TRUE); 
if (
$meta_value != '') echo $meta_value?> </td>
</tr>
</table>

  #14  
Old Sep 12, 2009, 08:36 AM
grasshopper
 
20 posts · Jun 2009
Thank you Flynn -

Yes, I am using atahualpa 3.4.2.

I reverted the functions/postinfo.php to its original version and inserted the suggested code into the post info item text area. it's clearly having some affect because, the organization field is coming back blank. I'm hoping there is a tweak, so that it actually brings back the value. could there be some conflict with the meta_values callback function in the .php file? I tried commenting it out, but then get a preg_replace error.

thanks so much Flynn for all of your help.

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 04:08 PM.


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