0

I'm trying to place the default featured image on the blog index page with an image to be determined by who the author of the post is. For some reason I'm getting the image for $author_id=2 even when the $author_id returns 3.

I've echoed my $author_id to make sure that it's returning the correct info, and it is. So something is wrong in the if statement itself.

Here's my code:

$author_id=the_author_meta('ID');

function default_image_fallback() { 
if(has_post_thumbnail()) {
    the_post_thumbnail();

}   else if($author_id = "2") {
    echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/jon-thumb.jpg' . '" alt="Jonathan Warner" />';


}   else if($author_id = "3") {
    echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/sam-thumb.jpg' . '" alt="Samuel Warner" />';        
}

else {
    echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumb.jpg' . '" alt="Samuel and Jonathan Warner" />';
}   
}

Here's the development site: http://bit.ly/1tMMbpy

I'm grateful for any help on this.

1
  • 1
    You are actually setting the $author_id to 2, you should be using the conditional comparator '==' in your else if statements
    – user42826
    Commented Oct 29, 2014 at 15:22

1 Answer 1

1

You are using wrong Comparison Operators.

Use

else if($author_id == "2") {

instead of

else if($author_id = "2") {

Edit: Try adding trailing slash after get_stylesheet_directory_uri function. its missing in your code.

<img src="<?php echo get_stylesheet_directory_uri() ?>/images/default-thumb.jpg" alt="" title="" width="" height="" />
2
  • Thank you - I actually tried the "==" instead and then nothing at all showed up, so I had gone back to the "=" instead. If anyone else needs this Brad Dalton cleaned it up nicely here: wpsites.net/web-design/…
    – Sddarter
    Commented Oct 30, 2014 at 16:20
  • You are missing a trailing slash. Edited my answer with an example.
    – gmatta
    Commented Oct 30, 2014 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.