Conditional in has_post_thumbnail

Asked

Viewed 25 times

2

Well I am setting up a theme that some posts will be presented a Thumb and others not, but I need to put a condition in the code that when Thumb has pull the config of Thumb and when it does not make a simple post. However in the present way he is trying to pull just the way he has Thumb

Here is the code with the configuration :

<div class="container">
    <div class="row">

        <!-- Main Content -->
        <div class="col-md-9 border-right">

            <div class="main-content" id="main">

                <div class="row">
                    <div class="col-md-12">
                        <div class="text-content center">
                            <?php the_content(); ?>
                        </div>
                    </div>
                </div>

                <ul class="result-list">
                    <?php 
                        $paged = get_query_var('paged');
                        query_posts('category_name=saude-caixa&paged='.$paged);
                    ?>
                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

                        <article class="blog-item-list">
                        <li class="result-item">
                            <div class="text-content">
                        <?php if(has_post_thumbnail($post->ID)); ?>
                                <div class="entry-image">
                                <img src="<?php the_post_thumbnail_url($post->ID, 'ag-apcef-large'); ?>" alt="<?php the_title(); ?>">
                                </div>

                                <a href="<?php the_permalink() ?>"><h2><?php the_title(); ?></h2></a>
                                <div class="entry-meta">

                                    <span class="entry-date"><i class="fa fa-clock-o"></i> <time><?= get_the_date(); ?></time></span>
                                </div>
                                <?php the_excerpt() ?>
                                <a href="<?php  the_permalink(); ?>" class="link">Ler Tudo</a>
                            </div>
                        </li>
                        </article>

                    <?php endwhile; endif;?>
                </ul>

                <?php

                the_posts_pagination( array(
                    'mid_size'  => 2,
                    'prev_text' => false,
                    'next_text' => false,
                    'screen_reader_text' => ' '
                ) );

                ?>

            </div>

        </div>

        <!-- Sidebar -->
        <div class="col-md-3" id="sidebar">
            <?php get_sidebar(); ?>
        </div>
    </div>

1 answer

1


Is missing close the if where you check if the thumbnail exists:

<?php if(has_post_thumbnail($post->ID)) : ?>
    <div class="entry-image">
        <img src="<?php the_post_thumbnail_url($post->ID, 'ag-apcef-large'); ?>" alt="<?php the_title(); ?>">
    </div>
<?php endif; ?>
  • Face the problem was fixed !!!! Vlw the problem was beyond the closure in condition " <?php if(has_post_thumbnail($post->ID)) : ? > "I had put "dot and comma" and not dot and dot !!! Thank you !

  • If nothing appears on the page, check the logs where the error is.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.