How to pull latest posts from a specific category

Question

I’m trying to pull the latest posts from the category "local-news" but I’m only seeing one of the two posts that exist for this category. I’m not sure if it’s my if statement and/or while loop that’s causing the issue. This is my first time developing a WP theme and using PHP so I’m a little confused as to how I could fix this. I’m not sure how to close my if statement or while loop either without causing a critical error or syntax error.

<?php
  $args = array(
  'category_name' => 'local-news',
  'post_type' => 'post' ,
  'orderby' => 'date' ,
  'order' => 'DESC' ,
  'posts_per_page' => 6
  );
  $q = new WP_Query($args);
  $q -> the_post();
  ?>
  if ( $q->have_posts() ) : { 
    while ( $q->have_posts() ) : the_post() {
      <div class="card-body pb-0">
        <div class="latest_news_cont">
          <a href="<?php the_permalink() ?>">
            <?php the_post_thumbnail(); ?>
          </a>

          <a href="<?php the_permalink() ?>">
            <h5>
              <?php the_title(); ?>
            </h5>
          </a>
          <?php the_excerpt(); ?>
          <p style="text-align:center;"><a href="<?php the_permalink() ?>" class="readmore_news">Read more</a></p>
          <br>

        </div>
      </div>
      <div class="card-body pb-0">
        <div class="latest_news_cont">
          <a href="<?php the_permalink() ?>">
            <?php the_post_thumbnail(); ?>
          </a>

          <a href="<?php the_permalink() ?>">
            <h5>
              <?php the_title(); ?>
            </h5>
          </a>
          <?php the_excerpt(); ?>
          <p style="text-align:center;"><a href="<?php the_permalink() ?>" class="readmore_news">Read more</a></p>
          <br>

        </div>
      </div>
0
Salem 3 months 0 Answers 20 views 0

Leave an answer