• tylerplack

    (@tylerplack)


    I am using this code:

    <?php
    if ( has_post_thumbnail() ) {
    echo the_post_thumbnail();
    }
    else {
    echo "";
    }
    ?>

    to get the post thumbnails from the blog. It’s setting up fine, but how do I make it display another image if there is none. You can see it is the PHP if and else statements, but I don’t know how to make to do an image.

    All help is appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    (@esmi)

    Try:

    <?php
    if ( has_post_thumbnail() )  echo the_post_thumbnail();
    else {
    	echo '<img src="https://domain/image.jpg" width="xx" height="yy" alt="" />';
    }
    ?>

    jwesonga

    (@jwesonga)

    I just tried that function has_post_thumbnail and got this error:

    Fatal error: Call to undefined function has_post_thumbnail() in C:\xampp\htdocs\wordpress-2.9.1\wordpress\wp-content\themes\mclabs\inner_page.php on line 11

    jwesonga

    (@jwesonga)

    Sorry figured it out, I added the add_theme_support( 'post-thumbnails' ); to my functions.php file and it sorted it out

    esmi

    (@esmi)

    Sorry. I assumed you already had that in place.

    Thread Starter tylerplack

    (@tylerplack)

    Great, esmi. How can we make this more dynamic?

    <?php
    if ( has_post_thumbnail() )  echo the_post_thumbnail();
    else {
    	echo '<img src="https://domain/image.jpg" width="xx" height="yy" alt="" />';
    }
    ?>

    See how it says domain/image.jpg? How can I do the <?php bloginfo('template_url'); ?> so it will work in all sites, but still inside this code?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post Image – Default for None’ is closed to new replies.