WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help with php conditions. (3 posts)

  1. mikelacroix
    Member
    Posted 2 years ago #

    I need a little help!

    I'm fully aware that this might be the noobyish noob problem ever, but my PHP skills are very rudimentary.

    What I want to do is to set up a condition where the beginning of an entry would return one of three results:

    1) A video
    2) If no video is set, a thumbnail
    3) If no thumbnail is set, nothing

    The video is embedded via a plug in.

    Here's what I have:

    <div class="entry">
    
    <?php if ( get_post_meta($post->ID, "_videoembed", true) || get_post_meta($post->ID, "_videoembed_manual", true) ): ?>
            <div class="video">
                <?php echo p75GetVideo($post->ID); ?>
            </div>
            <?php endif; ?>
    <?php
    if ( has_post_thumbnail() ) { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=200&w=490&zc=1" alt=""/></a>
    <?php } else { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.png" alt="" /></a>
    <?php } ?>
    <?php the_excerpt(); ?>
    <div class="clear"></div>
    </div>

    What am I doing wrong? I know it has something to do with if/else commands, but I'm lost as to what to do next.

    Many, many thanks in advance!

  2. hiteshanjara
    Member
    Posted 2 years ago #

    Hi,

    Try this

    <div class="entry">
    
    <?php if ( get_post_meta($post->ID, "_videoembed", true) || get_post_meta($post->ID, "_videoembed_manual", true) ) { ?>
            <div class="video">
                <?php echo p75GetVideo($post->ID); ?>
            </div>
    <?php } else if ( has_post_thumbnail() ) { ?>
    			<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=200&w=490&zc=1" alt=""/></a>
    <?php } else { ?>
    			<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.png" alt="" /></a>
    <?php } ?>
    
    <?php the_excerpt(); ?>
    
    <div class="clear"></div>
    </div>
  3. mikelacroix
    Member
    Posted 2 years ago #

    It worked like a charm! So basically, <?php } else if ( has_post_thumbnail() ) { ?> was the way to go. But I thought I needed an <?php endif; ?> to hold it all together.

    I just learned something! Thanks so much, hiteshanjara!

Topic Closed

This topic has been closed to new replies.

About this Topic