|
#1
Apr 13, 2010, 10:38 AM
|
|
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
Apr 15, 2010, 05:33 PM
|
|
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 09:57 PM.
|
#3
Apr 15, 2010, 07:10 PM
|
|
|
|
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
Apr 15, 2010, 09:55 PM
|
|
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
Apr 16, 2010, 06:34 AM
|
|
|
|
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 01:31 PM.
|
#6
Apr 16, 2010, 10:06 AM
|
|
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
Apr 16, 2010, 02:36 PM
|
|
|
|
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
Apr 16, 2010, 03:06 PM
|
|
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
Apr 16, 2010, 04:44 PM
|
|
|
|
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
Apr 16, 2010, 04:54 PM
|
|
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
Apr 16, 2010, 08:01 PM
|
|
|
|
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
Feb 6, 2013, 11:42 AM
|
|
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
Feb 6, 2013, 01:35 PM
|
|
|
|
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
Feb 6, 2013, 02:11 PM
|
|
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
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
|