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 » Center area post/pages »

Show custom field in kicker - only IF field value exists


  #1  
Old Apr 13, 2010, 09:38 AM
jaxon
 
27 posts · Jan 2010
Hi folks,

I'm using title images images for some page titles. To make these images appear, I'm using the technique detailed in this post: http://forum.bytesforall.com/showthread.php?t=1542 It put's the following code in the kicker page info item.

<a href="%permalink%"><img id="postheadingimg-%post-id%" class="postheadingimg" src="/path/to/images/%meta('postheadingimg')%" alt="%post-title%" /></a>

The basic concept is to add a custom field for header images. Then give that field a value corresponding to each page's header image. This works great, as long as a header image exists. If the custom field is not assigned to a page, I just get a "text output" of the page title.

So, the problem is that I need the custom field to ONLY display if it has a value. aka, if I assigned a header to the page. This would be easy peazy put it in a pie if I could pass custom fields to the loop, but.... Atahualpa doesn't support that. If it did, I could do something like this:

<? if (get_post_meta($post->ID, 'postheadingimg', true)) { ?>
<img src="<? bloginfo('url'); ?>/wp-content/page_titles/<? echo get_post_meta($post->ID, 'postheadingimg', true) ?>" alt="<? bloginfo('name'); ?>" />
<? } else { ?>
<?php bfa_post_headline('<div class="post-headline">','</div>'); ?>
<? } ?>

So.... The obvious solution seems to be using a if/else statement in the Page info items area of ATA. This is where I could use help. What would that code look like? Logically it would be...

Kicker:
If the header custom field has any value
show the value
Else
Show the current page title

Byline:
If the header has any value
show the current page title (this is for the search engines - so that there will always be H1 text but would then be move off screen with CSS)
Else
do nothing

I would then, just eliminate bfa_post_headline from the loop all together...

So, any ideas folks?
Thanks a ton for any suggestions!
  #2  
Old Apr 15, 2010, 04:33 PM
jaxon
 
27 posts · Jan 2010
So, I've made a bit of progress with this. I am now able to test whether or not my headerimage custom field has a value. This is very good. Now, if there is not a value - the default bfa headline is displayed.

The next step is the ELSE. If there IS a value - the value needs to be appended onto the root address for my title/header images. I am trying to achieve this by creating another variable $image that gets the default value of the root url + the value from the custom field. (note: the custom field values are file names like this: aboutus.gif)

I don't actually know my way around php at all, so any pointers would be really helpful. My two sticking points are:
-Creating an else statement that displays an image with a url taken from $image (I can't seem to add an else statement at all )
-Passing the $postheading variable to the $image variable. (I don't get how to pass the variable into the url intact)

Any advice - even guesses - would be enthusiastically appreciated.

Here's what I have.

<?php
$headerimage = get_post_custom_values("postheadingimg");
$image = "http://mydomain.net/wp-content/page_titles/".postheadingimg."";

if($headerimage == '') : ?>

<?php bfa_post_headline('<div class="post-headline">','</div>'); ?>

<?php endif; ?>

Last edited by jaxon; Apr 15, 2010 at 08:57 PM.
  #3  
Old Apr 15, 2010, 06:10 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
HTML Code:
<?php
$headerimage = get_post_custom_values("postheadingimg");
$image = "http://reneweb.net/wp-content/page_titles/".postheadingimg."";

if ($headerimage == '')  {
     bfa_post_headline('<div class="post-headline">','</div>');
     }
else {  
     ...else code goes here...
     }
?>
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #4  
Old Apr 15, 2010, 08:55 PM
jaxon
 
27 posts · Jan 2010
Beautiful, perfect, excellent juggledad! You are so stupidly helpful! Thank you thank you! I really don't know php semantics at all - so that was exactly what I needed.

If you or anyone else can spare a few more minutes... I still need help with passing the variable and actually displaying the image.

First - is the last part of the following line the correct way to pull this variable? With the surrounding periods and quotes ."stuff." ?

$image = "http://mydomain/wp-content/page_titles/".postheadingimg."";

Second, for the ELSE statement... This was my guess...

<img src="<?php echo $image; ?>" alt="" />


but it returns:
Parse error: syntax error, unexpected '<' in /wp-content/themes/atahualpa/functions.php(476) : eval()'d code on line 21

Thanks a ton. Once this is working, I'll write a nice overview as a new post for anyone trying to do something similar. Thanks again!
  #5  
Old Apr 16, 2010, 05:34 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
Quote:
First - is the last part of the following line the correct way to pull this variable? With the surrounding periods and quotes ."stuff." ?

$image = "http://mydomain/wp-content/page_titles/".postheadingimg."";
use single quotes and you have set $headerimage so use it instead, so you have
HTML Code:
$image = 'http://mydomain/wp-content/page_titles/' . $headerimage;
Quote:
Second, for the ELSE statement... This was my guess...

<img src="<?php echo $image; ?>" alt="" />

but it returns:
Parse error: syntax error, unexpected '<' in /wp-content/themes/atahualpa/functions.php(476) : eval()'d code on line 21
you have to be careful mixing HTML and PHP to escape things ar the right time. In this code
HTML Code:
if ($headerimage == '')  {
     bfa_post_headline('<div class="post-headline">','</div>');
     }
else {  
     ...else code goes here...
     }
the code that goes into the else is in PHP mode, so if you wanted to create HTML there you would need it to look like this
HTML Code:
if ($headerimage == '')  {
     bfa_post_headline('<div class="post-headline">','</div>');
     }
else {  
     ?> <img src=" <?php echo $image; ?>" alt="" /> <?php
     }
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support

Last edited by juggledad; Feb 6, 2013 at 12:31 PM.
  #6  
Old Apr 16, 2010, 09:06 AM
jaxon
 
27 posts · Jan 2010
You make this all seem so darn logical! Thank you juggledad!
The if else statement itself is perfectly functional now but there is some missing link for displaying the image. Currently the ELSE case just doesn't display anything. The code I'm using is below. It seems like the only two potential trouble areas are the way I'm calling the image url for $image or the ELSE statement itself. For reference, an actual image url for one of these images is: http://www.reneweb.net/wp-content/pa...es/contact.gif and the custom field gets the value contact.gif

This is the code I'm trying - based entirely on your excellent work



<?php
$headerimage = get_post_custom_values("postheadingimg");
$image = 'http://www.reneweb.net/wp-content/page_titles/'.$headerimage;

if ($headerimage == '') {
bfa_post_headline('<div class="post-headline">','</div>');
}
else {
?> <img src=" <?php echo $image; ?>" alt="" /> <?php
}
?>

Thanks for sticking with me on this.
  #7  
Old Apr 16, 2010, 01:36 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
Try this
HTML Code:
<?php
$headerimage = get_post_custom_values("postheadingimg");
$image = 'http://www.reneweb.net/wp-content/page_titles/'.$headerimage;

if ($headerimage == '') {
bfa_post_headline('<div class="post-headline">','</div>');
}
else { 
?> <img src=" <?php $image ?>" alt="" /> <?php
}
?>
What you want is to output a line of HTML that has location of the image. The ECHO was
Just printing it's contents on the screen. With this, it should create the HTML using the contents of $image as part of the HTML statement
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #8  
Old Apr 16, 2010, 02:06 PM
jaxon
 
27 posts · Jan 2010
So, the echo thing makes sense except that it wasn't printing anything to the screen before... With the new code, there is still nothing displayed where the image should be. I checked the source and this is the output for that space:

<img src=" " alt="" />

here's a page that should have an image if it's helpful at all: http://reneweb.net/projects/

Thank you so much for the quick replies Your help is really appreciated.
  #9  
Old Apr 16, 2010, 03:44 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
try it like this
HTML Code:
<?php
$headerimage = get_post_custom_values("postheadingimg");
$image = 'http://www.reneweb.net/wp-content/page_titles/'.$headerimage;

if ($headerimage == '') {
bfa_post_headline('<div class="post-headline">','</div>');
}
else { 
      echo '<img src="'.$image.'" alt="" />';
}
?>
after src= you have a double quote, single quote, a period, $image, a period, a single quote and a double quote
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #10  
Old Apr 16, 2010, 03:54 PM
jaxon
 
27 posts · Jan 2010
No go. The source is showing this for the output... A lot better than "" though

<img src="http://www.reneweb.net/wp-content/page_titles/Array" alt="" />

Thank you!
  #11  
Old Apr 16, 2010, 07:01 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
well your problem is that get_post_custom_values() is returning an ARRAY not a single value, that's why the word ARRAY is showing up at the end of the line.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #12  
Old Feb 6, 2013, 10:42 AM
rbiasiutti
 
34 posts · Mar 2011
Send a message via Skype™ to rbiasiutti
Hi,
i have the same request

1) I would like to insert a custom field named 'photo' in all posts and setting it with OK if a photo gallery is present and NO if not.

2) In the multipost page (created with the JUGGLEDAD's multicolumn/custom query template) the Kicker area must appear with an image if the custom field are setted to OK or blank (if disappear ... is better) if the field are setted to NO.

but i read ( and i read, and i re-read) this post but i don't understand where i must inserting the IF/ELSE code.

Do you explain me ?

Thank you
  #13  
Old Feb 6, 2013, 12:35 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
1) this thread is from 2010
2) you can no longer add PHP in the theme options as this poster did back in 2010
3) You will have to edit the template and put your code there.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #14  
Old Feb 6, 2013, 01:11 PM
rbiasiutti
 
34 posts · Mar 2011
Send a message via Skype™ to rbiasiutti
for this did not understand ... I was hoping it was still possible.

Quote:
Originally Posted by juggledad
3) You will have to edit the template and put your code there.
ok for this but ... where?
You may indicate me, please, a most precise part of template to edit?

Thank you
Riccardo

Bookmarks

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
How to change the font of comment field's title? Antonino Giglio Header configuration & styling 3 Mar 8, 2010 10:18 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] post - custom field isa Forum How-To 0 Sep 17, 2009 02:44 PM
Custom Field: Default Values gungo Atahualpa 3 Wordpress theme 13 Sep 12, 2009 08:36 AM


All times are GMT -6. The time now is 02:57 AM.


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