Alicia St Rose
asked on
Trying to create default featured image for blog post in Wordpress, but Code not working
Hi,
I'm building a parent theme from Seamless at Themehybrid. I'm needing to add the functionality of a default image displaying in blog archives when the client doesn't add a featured image and use main post image instead.
I found this code and I'm trying to make it work with the existing code in my theme's template file. When I replace the thumbnail code with this new code I lose the page content. So I'm trying to merge the two and this is what I've come up with, but it's not working either:
In Functions.php:
In my template file:
I'm building a parent theme from Seamless at Themehybrid. I'm needing to add the functionality of a default image displaying in blog archives when the client doesn't add a featured image and use main post image instead.
I found this code and I'm trying to make it work with the existing code in my theme's template file. When I replace the thumbnail code with this new code I lose the page content. So I'm trying to merge the two and this is what I've come up with, but it's not working either:
In Functions.php:
function selva_main_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment
&post_mime_type=image&order=desc');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', true);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$main=wp_get_attachment_url($num);
$template=get_template_directory();
$the_title=get_the_title();
print "<img src='$main' alt='$the_title' class='frame' />";
endif;
}
In my template file:
<?php if ( ( current_theme_supports( 'get-the-image' ) && (has_post_thumbnail())) {
echo get_the_image()
} else {
echo selva_main_image();
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adding the semi-colon didn't make much of a difference. Still getting the white screen of death. So I think the issue is bigger than that. jason1178 has provided a clue. I followed the trail and found that 'get-the-image' references a script in an extensions folder. The script has beaucoup options for images, one being the default image I'm looking for!
I set my default image in one of the options and Wow works like a charm. This script is so kickA$$ I'm attaching it below!
get-the-image.php
I set my default image in one of the options and Wow works like a charm. This script is so kickA$$ I'm attaching it below!
get-the-image.php
ASKER
You set me on the right track!
Thanks!
Thanks!
Line 2 needs ; (semicolon) at the end:
Open in new window