• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

Trying to create default featured image for blog post in Wordpress, but Code not working

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
  if($files) :
    $keys = array_reverse(array_keys($files));
    $num = $keys[$j];
    $image=wp_get_attachment_image($num, 'large', true);
    $imagepieces = explode('"', $image);
    $imagepath = $imagepieces[1];
    print "<img src='$main' alt='$the_title' class='frame' />";

Open in new window

In my template file:

<?php if ( ( current_theme_supports( 'get-the-image' ) && (has_post_thumbnail())) {
			 echo get_the_image()
			} else {
		   echo selva_main_image();

Open in new window

Alicia St Rose
Alicia St Rose
  • 2
1 Solution
Jason C. LevineNo oneCommented:
current_theme_supports( 'get-the-image' 

Open in new window

Where is get-the-image coming from?

Shouldn't it be get_the_image?
You have a code error in your template file code also. If you lose your content when trying the code, that could be why.

Line 2 needs ; (semicolon) at the end:

echo get_the_image();

Open in new window

Alicia St RoseOwner & Principle Developer/DesignerAuthor Commented:
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!
Alicia St RoseOwner & Principle Developer/DesignerAuthor Commented:
You set me on the right track!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now