เพิ่มรูปหมวดหมู่ ใน SMF ง่ายๆ

  • 0 replies
  • 5449 views
เพิ่มรูปหมวดหมู่ ใน SMF ง่ายๆ
« เมื่อ: มีนาคม 09, 2018, 11:11:22 PM »
เปลี่ยนจาก icon เดิมๆ ให้เป็น icon สีสันสดใน ในบอร์ดแต่ละหมวดหมู่ง่ายๆ

โดยปกติแล้ว ถ้าใช้ theme พื้นฐาน รูปประจำบอร์ดจะไม่ค่อยสวยสะดุดตาเท่าไหร่ ทีนี้เราก็แก้ไข หรือเพิ่มเติมรูปประจำหมวดหมู่ง่ายๆ ให้ SMF ของเราดูสดใสน่าชมยิ่งขึ้น

ทำได้โดย แก้ไฟล์ BoardIndex.template.php  เปิดไฟล์ขึ้นมาแล้วค้นหาคำว่า

/* Each board in each category's boards has:

จะเจอในส่วนที่เป็น code ดังนี้

อ้างถึง
         foreach ($category['boards'] as $board)
         {
            echo '
            <tr id="board_', $board['id'], '" class="windowbg4">
               <td class="icon" style="height:80px;">.....

ซึ่งแต่ละ theme ก็อาจจะมีรายละเอียดไม่เหมือนกัน แต่จะคล้ายๆ กัน คือการอ้างถึงตารางสำหรับ icon หน้าหมวดหมู่ โดยเริ่มต้นตั้งแต่

/* Each board in each category's boards has:
.
.
.
.
ไปจนจบ... loop ซึ่งสังเกตุบรรทัดสุดท้ายจะเป็น
// Has it outstanding posts for approval?

ทีนี้ใน loop เราจะปิดคำสั่งบางตัว หรือไม่ปิดก็ได้ แต่แนะนำว่าให้ปิดไปเลย เพราะไม่ค่อยได้ใช้ประโยชน์อะไรมาก
แล้วเพิ่ม code นี้เข้าไปต่อ code ด้านบน

โค๊ด: [Select]
<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '">
<img src="', $settings['images_url'], '/icon_main/' . $board['id'] . '.png" alt="" title="', $board['name'], '" />

หน้าตาจะประมาณนี้

อ้างถึง
         /* Each board in each category's boards has:
         new (is it new?), id, name, description, moderators (see below), link_moderators (just a list.),
         children (see below.), link_children (easier to use.), children_new (are they new?),
         topics (# of), posts (# of), link, href, and last_post. (see below.) */
         foreach ($category['boards'] as $board)
         {
            echo '
            <tr id="board_', $board['id'], '" class="windowbg4">
               <td class="icon" style="height:80px;"><a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '">
               <img src="', $settings['images_url'], '/icon_main/' . $board['id'] . '.png" alt="" title="', $board['name'], '" />';

            echo '
                  </a>
               </td>
               <td class="info">
                  <a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';

// Has it outstanding posts for approval?

แล้วที่เหลือก็ไปสร้าง folder ชื่อว่า icon_main เพิ่มเข้าไปใน images ของ theme ที่ใช้ ในตัวอย่างเป็นการเพิ่ม folder ชื่อว่า icon_main เข้าไป เช่น Themes/ชื่อ theme/images/icon_main

แล้วหารูปใส่เข้าไปใน folder ชื่อว่า icon_main นี้ โดยตั้งชื่อรูปตาม id ของบอร์ด  (ในตัวอย่างตั้งเป็นเลข 1-10 นามสกุลไฟล์เป็น .png)

เท่านี้ก็ได้รูป icon สวยๆ ให้กับบอร์ดของเราแล้ว