Wp_Query not showing featured post
-
I am currently working through a wordpress course and I am building the homepage of the wordpress website and have ran into an issue. I am trying to use the WP Query class to create a featured post however, the post is not being displayed. Here’s my code.
<section class="middle-area"> <div class="container"> <div class="row"> <aside class="sidebar col-md-3 h-100"> <?php // Require a file called sidebar-home.php get_sidebar( 'home' ); ?> </aside> <div class="news col-md-9"> <div class="row"> <div class="container"> <?php $featured = new WP_Query( 'post_type=post&posts_per_page=1&cat=4,11' ); if( $featured->have_posts() ): while( $featured->have_posts() ): $featured->the_post(); ?> <div class="col-12"> <?php get_template_part( 'template-parts/content', 'featured' ); ?> </div> <?php endwhile; wp_reset_postdata(); endif; ?> </div> </div> </div> </div> </div> </section>The content-featured file
<article <?php post_class( array( 'class' => 'featured' ) ); ?>> <h2><?php the_title(); ?></h2> <div class="thumbnail"> <?php the_post_thumbnail( 'large', array( 'class' => 'img-fluid' ) ); ?> </div> <div class="meta-info"> <p> by <span><?php the_author_posts_link(); ?></span> Categories: <span><?php the_category( ' ' ); ?></span> <?php the_tags( ' Tags: <span>', ', ', '</span>' ); ?> </p> <p><span><?php echo get_the_date(); ?></p> </div> <p><?php the_excerpt(); ?></p>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Wp_Query not showing featured post’ is closed to new replies.