Alex
Alex

Reputation: 929

How to display the image thumbnail outside of the_content() function in Wordpress

I am making a products page and I want to let the user to upload the image and show it according to the design (the thumbnail is placed at top, then the title and then the description) how can I place it outside the_content(); function

Here's my code:

    <section class="products">
        <?php query_posts( 'posts_per_page=8' ); ?>
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <article class="products__item">
                <div class="products__item--thumbnail">

                </div>
                <h2 class="products__item--title"><?php the_title(); ?></h2>
                <p class="products__item--info"><?php the_content(); ?></p>
                <h3 class="products__item--price">60.00</h3>
                <span class="fa fa-search products__item-cart"></span>
                <a href="<?php the_permalink(); ?>">test</a>
            </article>
        <?php endwhile; else : ?>
            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
        <?php endif; ?>
    </section>

Regards!

Upvotes: 0

Views: 700

Answers (1)

Ajith
Ajith

Reputation: 639

if you are using featured image and need to display it, place the code bellow where you need the image ( this should be within the loop )

<?php the_post_thumbnail(); ?>

or if you need to get the featured image's link, and display it as a img tag, you can use this code to get the src link of featured image

<?php $image = get_the_post_thumbnail();

Hope this answer helped you any sort

Upvotes: 1

Related Questions