user2333038
user2333038

Reputation: 31

Display different post-typ if the featured image exist or not

Hey I have a problem with my php code in wordpress. I want to have a different section class if there is a image or not. So I can make the text central if there is non image and make it float to right if there is.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<?php if(has_post_thumbnail() ); ?>
    <section class="post">
        <?php the_post_thumbnail('full'); ?>
        <div class="posts-data">
            <h2><?php the_title(); ?></h2>
            <p><?php the_excerpt(); ?></p>
        </div>
    </section>
<?php else: ?>
    <section class="post-no-img">
        <h2><?php the_title(); ?></h2>
        <p><?php the_excerpt(); ?></p>
    </section>
<?php endif; ?>

<?php endwhile; else: ?>

<p>There are no post or pages</p>

<?php endif; ?>

I get this worning:

Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\Fortagsida\wp-content\themes\foretagblog\front-page.php on line 12

Line 12 is .

Upvotes: 0

Views: 46

Answers (2)

TheWolf
TheWolf

Reputation: 1385

In line 3, it should be <?php if(has_post_thumbnail() ): ?> (: instead of ;)

Upvotes: 1

blue
blue

Reputation: 1949

You probably want to put ":" for the second if

Upvotes: 0

Related Questions