WordPress.org

Ready to get started?Download WordPress

Forums

Simple Else if Statement (2 posts)

  1. icey7
    Member
    Posted 1 year ago #

    Hi

    Thankyou for reading.

    I have a small code which displays post thumbnails, I would like to add an else/if statement so if this first method of creating thumbnails fails it create thumbnails using a second method.

    Here is what Im using so far to create thumbnails:

    <!--Begin post thumbnail-->
    <div class="postthumbcon">
    <?php
    // check if the post has a featured image assigned to it.
    if ( has_post_thumbnail() ) {
    // get the src of the large size featured image
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );
    $thumbnailSrc = $src[0];
    // output image resized with timthumb
    ?>
    <div class="postthumb">
    <a href="<?php the_permalink(); ?>">
    <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumbnailSrc; ?>&h=125&w=165" alt="">
    </a>
    </div>
    <?php } ?>
    </div>
    <!--end post thumbnail-->

    Here is where I would like to add the Else/if

    This next code is the Second method of creating thumbnails:

    <?php if( get_post_meta($post->ID, "thumb", true) ): ?>
    <div class=”homethumb”>
    <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&h=150&w=150&zc=1" alt="<?php the_title(); ?>" width="150" height="150" />
    </div>
    <?php else: ?>
    <?php endif; ?>

    Thankyou again
    Kind regards

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try and see if you can get on with this php tutorial:

    http://php.net/manual/en/control-structures.elseif.php

Topic Closed

This topic has been closed to new replies.

About this Topic