#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Hi Simple Wordpress If/Else Question (Solved)


    Hi

    Ive been looking around for awhile trying to solve this.

    I have two different methods for displaying Wordpress Thumbnails

    What I would like to do is, display the first method, and if it is not available then to display thumbs using the second method.

    Below are the Two Methods for displaying Post Thumbnails.

    Method 1
    Code:
    <!--Begin WordPress Featured 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">
    ">
    <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumbnailSrc; ?>&h=125&w=165" alt="">
    
    </div>
    <?php } ?>
    </div>
    <!--end WordPress Featured post thumbnail-->
    Here is the second method.
    Code:
    <!--Begin Timthumb thumbnail-->
    <?php // This will show the image and link the image to the post. Alter the width and height (in both places) to your needs. ?>
    
    <?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?>
    <div class="postthumb">
    " rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><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 } ?>
    
    <!--End Timthumb thumbnail-->

    So basically it would read Like

    if (firstmethod) {
    Display first method;
    }
    else {
    display second method'
    }

    Any suggestions would be appreciated

    Thankyou
    Kind regards
    .....................................................................................

    Hey thankyou, I have solved this issue.

    Below is the full working code.

    <div class="postthumbcon">
    <?php
    if ( has_post_thumbnail() ) {
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );
    $thumbnailSrc = $src[0];
    ?>
    <div class="postthumb">
    <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumbnailSrc; ?>&h=125&w=165" alt="" />
    </div>
    <?php } else if ( get_post_meta($post->ID, 'thumb', true) ) { ?>
    <div class="postthumb">
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <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" />
    </a>
    </div>
    <?php } ?>
    </div>


    thanks again

    Comments on this post

    • ManiacDan agrees : Bam!
    Last edited by icey; August 8th, 2012 at 06:16 AM. Reason: Fixed Spelling
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    12
    Rep Power
    0
    Thanks for the solution, I got such a problem before, & Solved it !

IMN logo majestic logo threadwatch logo seochat tools logo