WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got this code to show video loops on my blog. It's working nicely.


function catch_video() {
  global $post, $posts;
  $first_vid = '';
  $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_vid = $matches [1] [0];
  echo '<iframe width="100%" height="400" src="';
  echo $first_vid;
  echo '" frameborder="0" allowfullscreen></iframe>';

It is shown by the code in the loop: <?php catch_video();?>

Now, I would like that when it was posted a featured image instead of the video, it showed a code of mouse hover (I already have it ready), so I created this code but something is wrong with it:

<?php $blog = new WP_Query($args); ?>
<?php while( have_posts() ): the_post(); ?>

   <?php if(has_post_thumbnail()): ?>

   <!-- Hover Image -->
     <div class="image-wrapper-hover">
        <!-- hover-content -->
        <?php the_post_thumbnail('large');?>
   <!-- close Hover Image -->   

   <?php else ?>

      <?php catch_video();?>

   <?php endif ?>

Anyone knows what is wrong?

share|improve this question
What problem are you having? Are you getting any errors? – Joseph Leedy Jan 22 '13 at 2:24
up vote 0 down vote accepted

At first blush, it appears that you are missing a colon from your else statement. Without more info, though, I cannot tell you anything else.

<?php if( has_post_thumbnail() ) : ?>

    <div class="image-wrapper-hover">
        <?php the_post_thumbnail( 'large' ); ?>

<?php else : ?>

    <?php catch_video();?>

<?php endif; ?>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.