/* ===== CONTAINER: không dính lề, nhìn thoáng hơn ===== */
.category-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* ===== GRID ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
}

/* ===== CARD ===== */
.card {
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  transition: all 0.35s ease;
  box-shadow: 0 8px 25px rgba(0,0,0,0.06);
  border: 1px solid #f1f1f1;
}

/* Hover mượt hơn */
.card:hover {
  transform: translateY(-8px);
  box-shadow: 0 18px 40px rgba(0,0,0,0.12);
}

/* ===== IMAGE ===== */
.card-img {
  display: block;
  overflow: hidden;
  border-bottom: 1px solid #eee;
}

.card-img img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  transition: 0.4s ease;
}

/* zoom nhẹ */
.card:hover .card-img img {
  transform: scale(1.08);
}

/* ===== CONTENT ===== */
.card-content {
  padding: 18px 16px 20px;
}

/* TITLE */
.card-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 10px;
}

.card-title a {
  color: #1a1a1a;
  text-decoration: none;
}

.card-title a:hover {
  color: #007bff;
}

/* DESC */
.card-desc {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
}

/* ===== PAGINATION đẹp hơn ===== */
.pagination {
  text-align: center;
  margin-top: 50px;
}

.pagination .page-numbers {
  display: inline-block;
  margin: 5px;
  padding: 8px 14px;
  border-radius: 8px;
  background: #f2f2f2;
  text-decoration: none;
  color: #333;
  transition: 0.3s;
}

.pagination .page-numbers:hover {
  background: #007bff;
  color: #fff;
}

.pagination .current {
  background: #007bff;
  color: #fff;
}

/* ===== MOBILE FIX ===== */
@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .category-container {
    padding: 25px 15px;
  }

  /* Căn giữa nội dung */
  .card-content {
    text-align: center;
  }

  .card-title {
    font-size: 16px;
  }

  .card-desc {
    font-size: 13.5px;
  }
}

/* ===== TABLET ===== */
@media (max-width: 1024px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}















<?php get_header(); ?>

<section class="category-container">
    
    <div style="text-align:center; margin-bottom:40px;">
        <h1 style="font-size:28px; font-weight:800;">
            <?php single_cat_title(); ?>
        </h1>
    </div>

    <div class="grid">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            
            <div class="card">
                
                <a href="<?php the_permalink(); ?>" class="card-img">
                    <?php if (has_post_thumbnail()) { 
                        the_post_thumbnail('medium'); 
                    } else { ?>
                        <img src="https://via.placeholder.com/400x250" alt="<?php the_title(); ?>">
                    <?php } ?>
                </a>

                <div class="card-content">
                    
                    <h2 class="card-title">
                        <a href="<?php the_permalink(); ?>">
                            <?php the_title(); ?>
                        </a>
                    </h2>

                    <div class="card-desc">
                        <?php echo wp_trim_words(get_the_excerpt(), 20); ?>
                    </div>

                </div>

            </div>

        <?php endwhile; endif; ?>
    </div>

    <!-- PAGINATION -->
    <div class="pagination">
        <?php
        the_posts_pagination(array(
            'mid_size'  => 2,
            'prev_text' => '← Trước',
            'next_text' => 'Sau →',
        ));
        ?>
    </div>

</section>

<?php get_footer(); ?>




function custom_category_posts_per_page($query) {
    if (!is_admin() && $query->is_main_query() && is_category()) {
        $query->set('posts_per_page', 9);
    }
}
add_action('pre_get_posts', 'custom_category_posts_per_page');