- This topic is empty.
-
AuthorPosts
-
March 31, 2010 at 10:51 am #28577
EamonnMac
MemberHey guys,
I’m working on a parent page that basically consists of nothing more than a big list of its child pages. The title of each child page is given, along with a thumbnail and some basic excerpt details via custom fields and get_post_meta. So far so good. Where I’m falling down is what happens when a custom field is requested and it’s not there, and how to then replace that missing data with default data. I can manage it no probs with the thumbnail, but not for the excerpt. The page isn’t live I’m afraid – but here’s the code I’m using:
Code:$excerptPath = get_post_meta($post->ID, “excerpt”, true);
if($excerptpath ==””) {
$excerptpath = “We haven’t included any text here yet, but we hope to have done so shortly!”;
}If the ‘excerpt’ custom field is not present, however, the dummy text doesn’t show. This exact syntax works fine for the thumbnail custom field (replacing it with a fallback img path). Why doesn’t it work in this case?
Thanks in advance! Any help appreciated.
March 31, 2010 at 11:36 am #73209Chris Coyier
KeymasterTry this:
Code:$excerptPath = get_post_meta($post->ID, “excerpt”, true);
if($excerptpath) {
$excerptpath = “We haven’t included any text here yet, but we hope to have done so shortly!”;
}March 31, 2010 at 12:14 pm #73211EamonnMac
MemberNo Joy…
I figure that the code is correct, (‘coz that’s basically what’s in the Codex) but that I’m putting it in the wrong place.
Here’s the whole page (not too big!):
Code:ID, “intro”, true); ?>
100, ‘post_type’ =>’page’, ‘post_parent’ => 337, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ));
while (have_posts()) {
the_post();
$thumbpath = get_post_meta($post->ID, ‘thumbnail’, true);
if($thumbpath ==””) {
$thumbpath = ‘/images/logo/logo_pic_coming_soon_200.gif’;
}
?>Again, any help greatly appreciated! :D
April 5, 2010 at 9:35 am #73533EamonnMac
MemberAny luck?
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.