![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
|
Wordpress Ninjas help please: Conditional IF statement using a custom field..
Google was no help so again I turn to the community. I have some site that I used themes on that needed to have a custom field for the thumbnail (before featured images) like this :
Code:
<?php echo get_post_meta($post->ID, thumb, true); ?>
__________________
High Performance Vps $10 Linode Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
The Codex link for get_post_meta, get_the_post_thumbnail:
http://codex.wordpress.org/Function_.../get_post_meta http://codex.wordpress.org/Function_...post_thumbnail Something like this probably: Code:
if ( $my_thumb = get_post_meta($post->ID, 'thumb', true) ) { // $my_thumb contains your value } elseif ( $my_thumb = get_the_post_thumbnail($post->ID, 'thumbnail') ) { // $my_thumb contains your value } else { // display the placeholder image }
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Beer Money Baron
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
|
UNTESTED:
Something like this might be easier to manage, add to your theme functions.php file: Code:
function get_custom_thumb( $post_id ) { // get_post_meta returns a string if ( $my_thumb = get_post_meta($post_id, 'thumb', true) ) { return '<img src="' . $my_thumb . '">'; } // get_the_post_thumbnail returns the html img src if ( $my_thumb = get_the_post_thumbnail($post_id, 'thumbnail') ) { return $my_thumb; } // return your own html placeholder image return '<img src="http://yoursite.com/image.jpg" />'; } Code:
<?php echo get_custom_thumb( $post->ID ); ?>
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
|
![]() ![]()
__________________
High Performance Vps $10 Linode Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: Apr 2002
Location: State Of Bliss
Posts: 2,438
|
Nice, I could use this too.
Thanks Brujah. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |