What is the proper way to display the posts featured image
-
Hello, I am creating a blog page and have setup multiple queries and pagination. The queries and pagination are working. I can see the titles of the posts populating but for some reason i am not seeing the images.
to display the images i used get_the_post_thumbnail_url() in the src if the image tag. Im guessing this may not be the right way to do it as the images are not displaying.
Im hoping I can get an answer here as to the right way to display the images. Any help is greatly appreciated. Here is the code i have so far.
<?php get_header(); ?> <section class="bu-header-img-container"> <img src="/wp-content/uploads/2023/09/bdl-life-static-header-9-23-1.jpg" alt=""> </section> <section class="bu-title-bar-container bu-page-width"> <div class="col-4 bu-title-left-column"> <h2 class="bu-yellow-title">Travel Inspiration</h2> </div> <div class="col-8 bu-title-right-column"> <hr class="bu-black-line"> </div> </section> <section class="bu-feature-section bu-page-width"> <?php $featurePosts = new WP_Query(array( 'category_name' => 'travel-inspiration-feature', 'posts_per_page' => 1 )); if ($featurePosts->have_posts()) : while ($featurePosts->have_posts()) : $featurePosts->the_post(); ?> <div class="bu-feature-post-container"> <img class="bu-img" src="<?php the_field('blue-section-feature-img'); ?>" alt=""> <hr class="bu-yellow-line"> <h2><?php the_title(); ?></h2> </div> <?php endwhile; endif; ?> <?php $secondaryPosts = new WP_Query(array( 'category_name' => 'travel-inspiration-secondary', 'posts_per_page' => 1 )); if ($secondaryPosts->have_posts()) : while ($secondaryPosts->have_posts()) : $secondaryPosts->the_post(); ?> <div class="bu-secondary-post-container"> <img class="bu-img" src="<?php get_the_post_thumbnail_url(); ?>" alt=""> <hr class="bu-yellow-line"> <h2><?php the_title(); ?></h2> </div> <?php endwhile; endif; ?> </section> <section class="bu-posts bu-page-width"> <?php $ourCurrentPage = get_query_var('paged'); $mainPosts = new WP_Query(array( 'category_name' => 'travel-inspiration', 'posts_per_page' => 12, 'paged' => $ourCurrentPage )); if ($mainPosts->have_posts()) : while ($mainPosts->have_posts()) : $mainPosts->the_post(); ?> <div class="bu-post"> <img src="<?php get_the_post_thumbnail_url(); ?>" alt=""> <hr class="bu-yellow-line"> <h2><?php the_title(); ?></h2> </div> <?php endwhile; ?> <div class="pagination-container"> <?php echo paginate_links(array( 'total' => $mainPosts->max_num_pages )); ?> </div> <?php endif; ?> </section> <section class="bu-page-width bu-pagination-container"> <img src="pagination-img.png" alt=""> </section> <section class="bu-page-width bu-bottom-img-links-container"> <div class="bu-bottom-img-links-left"> <h2>Book Now</h2> </div> <div class="bu-bottom-img-links-right"> <h2>Parking<br>Options</h2> </div> </section> <?php get_footer(); ?>
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘What is the proper way to display the posts featured image’ is closed to new replies.