Indytheme Support

ถาม - ตอบ => Smart Variety => ข้อความที่เริ่มโดย: indytheme-106 ที่ 28/02/23 เวลา 13:50 น.

หัวข้อ: แถบ recent post ด้านข้าง ปรับเฉพาะหมวดหมู่ได้ไหม
เริ่มหัวข้อโดย: indytheme-106 ที่ 28/02/23 เวลา 13:50 น.
ผมอยากปรับแถบ Recents post ด้านข้างให้แสดงเฉพาะรายการบทความในหมวดหมู่ที่กำหนดได้ไหม

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

(https://support.indytheme.com/uploads/images/indytheme-recent-post-1677566909.png)

ขอบคุณครับ :)
หัวข้อ: Re: แถบ recent post ด้านข้าง ปรับเฉพาะหมวดหมู่ได้ไหม
เริ่มหัวข้อโดย: SUPPORT ที่ 02/03/23 เวลา 20:40 น.
ตรงนี้ไม่สามารถจากธีมได้ครับผม
หัวข้อ: Re: แถบ recent post ด้านข้าง ปรับเฉพาะหมวดหมู่ได้ไหม
เริ่มหัวข้อโดย: smart-variety245 ที่ 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,
    ));