แถบ recent post ด้านข้าง ปรับเฉพาะหมวดหมู่ได้ไหม

392 2

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ผมอยากปรับแถบ Recents post ด้านข้างให้แสดงเฉพาะรายการบทความในหมวดหมู่ที่กำหนดได้ไหม

ตรงกรอบสีน้ำเงิน อย่างเช่น ให้แสดงเฉพาะบทความที่อยู่ใน หมวดหมู่ เที่ยวรอบโลก เท่านั้น



ขอบคุณครับ :)

Re: แถบ recent post ด้านข้าง ปรับเฉพาะหมวดหมู่ได้ไหม
« ตอบกลับ #1 เมื่อ: 02/03/23 เวลา 20:40 น. »
ตรงนี้ไม่สามารถจากธีมได้ครับผม

Re: แถบ recent post ด้านข้าง ปรับเฉพาะหมวดหมู่ได้ไหม
« ตอบกลับ #2 เมื่อ: 19/08/23 เวลา 22:56 น. »
แก้โค้ดครับ ตามนี้ครับ

template-parts/recent-posts-2.php
จาก
$the_query = new WP_Query(array(
        'post__not_in' => array($postid),
        'posts_per_page' => 4,
    ));

แก้เป็น

$category_detail = get_the_category($postid);
   foreach($category_detail as $ci) {
      $the_cat_id = $ci->cat_ID;
   }
    $the_query = new WP_Query(array(
        'cat' => $the_cat_id,
        'post__not_in' => array($postid),
        'posts_per_page' => 4,
    ));