Wordpress Posts in html site

Asked

Viewed 59 times

-1

I am trying to put images from my blog that is in Wordpress on my html site

My code

<?php while (have_posts()): the_post(); ?>
                        <div class="col-md-4 ">
                            <div class="box-blog">
                                <img src="" >
                                <h4 class="hov"><?php the_title(); ?></h4>
                                <span><i class="fa">&#xf073;</i> <?php the_time("d/m/Y"); ?></span>
                                <br><br>
                                <article>
                                    <?php the_excerpt(); ?>
                                </article>
                                <div align="center">
                                    <a target="__blank" href="<?php the_permalink(); ?>"><button class="btn btn-primary">Leia Mais</button></a>
                                </div>
                            </div>
                        </div>
                    <?php endwhile;?>

I already have the whole body just missing the image but I do not know how to put it please help me.

1 answer

1

You can use the the_post_thumbnail('thumbnail');, thus:

<?php while (have_posts()): the_post(); ?>
    <div class="col-md-4 ">
        <div class="box-blog">
            <!-- <img src="" > -->
            <?php the_post_thumbnail('thumbnail'); ?>
            <h4 class="hov"><?php the_title(); ?></h4>
            <span><i class="fa">&#xf073;</i> <?php the_time("d/m/Y"); ?></span>
            <br><br>
            <article>
                <?php the_excerpt(); ?>
            </article>
            <div align="center">
                <a target="__blank" href="<?php the_permalink(); ?>"><button class="btn btn-primary">Leia Mais</button></a>
            </div>
        </div>
    </div>
<?php endwhile;?>

or use get_the_post_thumbnail_url(get_the_ID(), 'full');, thus:

<?php while (have_posts()): the_post(); ?>
    <div class="col-md-4 ">
        <div class="box-blog">
            <?php $image = get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>
            <?php if( $image ): ?>
                <img src="<?php echo $image ?>" alt="<?php the_title(); ?>">
            <?php endif; ?>
            <h4 class="hov"><?php the_title(); ?></h4>
            <span><i class="fa">&#xf073;</i> <?php the_time("d/m/Y"); ?></span>
            <br><br>
            <article>
                <?php the_excerpt(); ?>
            </article>
            <div align="center">
                <a target="__blank" href="<?php the_permalink(); ?>"><button class="btn btn-primary">Leia Mais</button></a>
            </div>
        </div>
    </div>
<?php endwhile;?>

Follow the link to the documentation:

Browser other questions tagged

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