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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-29-2012, 12:29 PM   #1
tonyparra
Confirmed User
 
tonyparra's Avatar
 
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); ?>
Now that im adding content to these sites im using either a featured image or placeholder image. How can i correctly write the if statement to include the custom field first then if that isnt there the featured image and finally if that isnt there the placeholder image or code (i really want to use some ad script) .Someone please help with this I keep getting the white screen so i know im doing it wrong.
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-29-2012, 12:38 PM   #2
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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
}
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-29-2012, 12:47 PM   #3
Brujah
Beer Money Baron
 
Brujah's Avatar
 
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" />';
}
Then, in your template just use this where you want it displayed:
Code:
<?php echo get_custom_thumb( $post->ID ); ?>
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-29-2012, 01:41 PM   #4
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,319
yeppers
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-01-2012, 07:27 AM   #5
tonyparra
Confirmed User
 
tonyparra's Avatar
 
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
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-01-2012, 08:27 AM   #6
The Dawg
Confirmed User
 
The Dawg's Avatar
 
Join Date: Apr 2002
Location: State Of Bliss
Posts: 2,438
Nice, I could use this too.

Thanks Brujah.
The Dawg is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.