Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to include custom field data in Prettyphoto? WordPress

  • REFUNDED

I'm currently using Advanced Custom Fields to create a custom field has_the_portrait_sold which will be indicated on my Prettyphoto / Lightbox item.

However, when I use PHP from the example (it is true or false):

if(get_field('has_the_portrait_sold')){
echo "The item has been sold.";
}else{
echo "The item has not been sold";
}


In header.php:

<script type text/javascript>
jQuery(document).ready(function($) {
$("a[href$='.jpg'], a[href$='.jpeg'],
a[href$='.gif'], a[href$='.png']").prettyPhoto({
theme: 'dark_square',
show_title: true, /* true/false */
social_tools: '<?php the_title(); ?> <?php
if(get_field('has_the_portrait_sold')){
echo "do something";
}else{
echo "do something else";
}
?>'
});
});
</script>


However, while this may include the custom field in the lightbox as needed, it apparently only displays custom field data for the current page. I am needing custom field data to print for the current lightbox item / WordPress' image attachment.

I therefore tried including the custom field call in post-template.php. [[LINK href="http://wordpress.stackexchange.com/questions/55571/adding-custom-field-to-lightbox-in-header-only-pulls-current-page-data-not-ligh"]]I've been told this is not recommended[[/LINK]].

However, while this may include the custom field in the lightbox as needed, it apparently only displays custom field data for the current page. I am needing custom field data to print for the current lightbox item / WordPress' image attachment.

I therefore tried including the custom field call in post-template.php. Please note my PHP skills are limited, I am VERY determined to make this work.

return apply_filters( 'wp_get_attachment_link', "<a title='$post_title'
href='$url'>$link_text</a><?php
if(get_field('has_the_portrait_sold')){
echo "do something";
}else{
echo "do something else";
}
?>", $id, $size, $permalink, $icon, $text );
}


[[LINK href="http://wordpress.stackexchange.com/questions/55571/adding-custom-field-to-lightbox-in-header-only-pulls-current-page-data-not-ligh"]]I was given a brief explanation at StackExchange[[/LINK]], however, I just need someone to spell it out for me. Tell me what I need to do to get my custom field to show up in my lightbox. I'm desperate. Thanks.

Answers (2)

2012-06-20

Romel Apuya answers:

I think the onw you need to edit is the prettyphoto.php

im not just sure how does the code look like or is integretad in the theme
but if you give me access i can probably help and explain to you,


cheers,


AndrewJohn comments:

PrettyPhoto is not PHP based. It is based on Jquery. Take a look at the documentation here and send your recommendation: http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation/


Romel Apuya comments:

of course their are other prettyphoto that is PHP based.

can you share your original functions.php code?



AndrewJohn comments:

My theme's functions.php is at http://pastebin.com/bWsGykFi


Romel Apuya comments:

just use single qoute in the echo of do something

return apply_filters( 'wp_get_attachment_link', "<a title='$post_title' href='$url'>$link_text</a>
if(get_field('has_the_portrait_sold')){
echo 'do something';
}else{
echo 'do something else';
}
?>", $id, $size, $permalink, $icon, $text );
}


AndrewJohn comments:

I copied your code exactly and included it at the end of functions.php and I received this error:

Parse error: syntax error, unexpected '}' in /home/andrewsa/public_html/ra/newmasters/wp-content/themes/v1/functions.php on line 874


Romel Apuya comments:

remove the extra } of your function.php line 890 on the pastebin code.


Romel Apuya comments:

http://pastebin.com/eCWUEUvP


AndrewJohn comments:

[[LINK href="http://tinyurl.com/7mqpt6r
"]]'Do something else' prints above my gallery[[/LINK]]. How do I get this to show up on my lightbox?

Plus now I'm getting this error in post.php in wp-admin:

Warning: Cannot modify header information - headers already sent by (output started at /home/andrewsa/public_html/ra/newmasters/wp-content/themes/v1/functions.php:1) in /home/andrewsa/public_html/ra/newmasters/wp-includes/pluggable.php on line 866


AndrewJohn comments:

*corrected link: http://tinyurl.com/7mqpt6r

2012-06-20

Arnav Joy answers:

you have to use your this code return apply_filters( 'wp_get_attachment_link', "<a title='$post_title'

href='$url'>$link_text</a><?php

if(get_field('has_the_portrait_sold')){

echo "do something";

}else{

echo "do something else";

}

?>", $id, $size, $permalink, $icon, $text );

}


in functions.php and not in post-template.php


AndrewJohn comments:

Am I including this code in my theme's functions.php or WordPress' functions.php? I tried inserting it into my theme's functions.php and I received this error:

Parse error: syntax error, unexpected T_DO in /home/andrewsa/public_html/ra/newmasters/wp-content/themes/v1/functions.php on line 870


Arnav Joy comments:

share your original theme's functions.php here


AndrewJohn comments:

http://pastebin.com/bWsGykFi


Arnav Joy comments:

here is the new full code of functions.php

http://pastebin.com/wAPSYT02


AndrewJohn comments:

I copied the entire file and replaced my theme's functions.php and I received this error:

Parse error: syntax error, unexpected '}' in /home/andrewsa/public_html/ra/newmasters/wp-content/themes/v1/functions.php on line 862


Arnav Joy comments:

give me original functions.php
not that one which you given last time after adding your code , i need to see original functions.php


AndrewJohn comments:

Here is functions.php without code: http://pastebin.com/tdNAqxJw


Arnav Joy comments:

try this
http://pastebin.com/LkC8W0YE


AndrewJohn comments:

'do something' shows up above my gallery now. how do i get this to show in my lightbox? http://tinyurl.com/7mqpt6r


Arnav Joy comments:

where you want to show it in caption?


AndrewJohn comments:

Anywhere in the lightbox is fine. I can always style it later with CSS