Posts & Category display
-
Hello,
I’m learning how to write loops and what not, problem is I am trying to create a custom category page, I’ve managed to slowly write a query to pull in 5 posts from a specific category but it’s only displaying one. Is there anything wrong with my code below? (obviously there is!).
<?php get_header('topbar'); ?> <div class="blog_container"> <h2 class="blog-title"> Latest News </h2> <p> News information and much more. </p> </div> <?php // the query $the_query = new WP_Query(array( 'category_name' => 'my-category-slug', 'post_status' => 'publish', 'posts_per_page' => 6, )); ?> <?php if ($the_query->have_posts()) : ?> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <?php the_category(', '); ?> <?php the_title(); ?> <?php the_excerpt(); ?> <?php the_post_thumbnail(); ?> <?php the_content(); ?> <?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php endif; ?> <div class="container bloglist"> <div class="blog_list_outter"> <div class="blog_author"> <div class="author_image"><?php echo get_avatar( get_the_author_meta('ID'), 60); ?></div> </div> <div class="post-grid"> <h2 class="blog_heading"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h2> <div class="category_title"> <div class="category__list__card"> <p class="cat"> <?php echo get_the_category_list(', '); ?> </p> </div> <div class="post__stamp"> <?php the_time('F j, Y'); ?> </div> </div> </div> </div> </div> <?php get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Posts & Category display’ is closed to new replies.