WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show default placeholder image without link (2 posts)

  1. vikkineal
    Member
    Posted 1 year ago #

    Hi there

    Can anyone help?

    I'm trying to show a default placeholder image on my posts when the user hasn't uploaded an image.

    I have the below code BUT i need to rewrite it so that the link to the lightbox isn't applied to the placeholder image - only the uploaded image.

    Unfortunately my PHP isn't great at all so would appreciate some help..

    <div class="imageContainer"><a href="<?php the_permalink(); ?>">
            <?php if ( has_post_thumbnail($post->ID)) {
        echo get_the_post_thumbnail($post->ID, 'size-2');
     }else{
        echo '<img src="http://2.bp.blogspot.com/-DXmE0_mUAtg/TV5XC1JDN2I/AAAAAAAAAvc/_jdxdJATQHQ/s320/guard-cat.jpg"/>';
     }?>
            </a></div>
  2. vikkineal
    Member
    Posted 1 year ago #

    <div class="imageContainer">
        <?php if ( has_post_thumbnail() ) : ?>
            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('size-2'); ?></a>
        <?php else : ?>
            <img src="<?php echo get_bloginfo( 'stylesheet_directory' ); ?>/images/shared/placeholder.jpg" />
        <?php endif; ?>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic