สอนสร้าง Plugin WordPress (14) : ตัวอย่างการสร้าง Custom Taxonomy จัดการประเภท Post type

แชร์ ความรู้สำหรับพัฒนา plugin ของ Wordpress

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

สอนสร้าง Plugin WordPress (14) : ตัวอย่างการสร้าง Custom Taxonomy จัดการประเภท Post type

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

Custom Taxonomy เปรียบเสมือน Categories เป็นการจัดหมวดหมู่เนื้อหาต่างๆ ซึ่งเราสามารถที่จะ สร้าง Custom Taxonomy เพื่อมาจัดการเฉพาะ Post type ของเราได้
เเละสามารถเพิ่มคุณสมบัติได้ เช่น การเปลียนชื่อ button ต่างๆ เเถบจะเหมือนกับการสร้าง Custom Post type

ตัวอย่างการใช้งาน

โค้ด: เลือกทั้งหมด

add_action( 'init', 'create_book_tax' );

function create_book_tax() {
  register_taxonomy(
    'Category Books',
    'book',
    array(
      'label' => __( 'Category Books' ),
      'rewrite' => array( 'slug' => 'Category Books' ),
      'hierarchical' => true,
    )
  );
} 

โค้ด: เลือกทั้งหมด

add_action( 'init', 'codex_book_init' );

/**
 * Register a book post type.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 */
function codex_book_init() {
  $labels = array(
    'name'               => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
    'singular_name'      => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
    'menu_name'          => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
    'name_admin_bar'     => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
    'add_new'            => _x( 'Add News Demo', 'book', 'your-plugin-textdomain' ),
    'add_new_item'       => __( 'Add New Book', 'your-plugin-textdomain' ),
    'new_item'           => __( 'New Book', 'your-plugin-textdomain' ),
    'edit_item'          => __( 'Edit Book', 'your-plugin-textdomain' ),
    'view_item'          => __( 'View Book', 'your-plugin-textdomain' ),
    'all_items'          => __( 'All Books', 'your-plugin-textdomain' ),
    'search_items'       => __( 'Search Books', 'your-plugin-textdomain' ),
    'parent_item_colon'  => __( 'Parent Books:', 'your-plugin-textdomain' ),
    'not_found'          => __( 'No books found.', 'your-plugin-textdomain' ),
    'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )
  );

  $args = array(
    'labels'             => $labels,
    'description'        => __( 'Description.', 'your-plugin-textdomain' ),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'show_in_nav_menus' => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'book' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  );

  register_post_type( 'book', $args );
}



add_action( 'init', 'create_book_tax' );

function create_book_tax() {
  register_taxonomy(
    'Category Books',
    'book',
    array(
      'label' => __( 'Category Books' ),
      'rewrite' => array( 'slug' => 'Category Books' ),
      'hierarchical' => true,
    )
  );
} 
รูปภาพ

รูปภาพ

ศึกษาเพิ่มเติมได้ที่นี่
https://codex.wordpress.org/Function_Re ... r_taxonomy
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41131
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: สอนสร้าง Plugin WordPress (14) : ตัวอย่างการสร้าง Custom Taxonomy จัดการประเภท Post type

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

รวมกระทู้ บทความสอนสร้าง Plugin WordPress
https://www.mindphp.com/forums/viewtopic ... 25&t=36079
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ฮา เป็นคนไปเรื่อย
PHP Newbie
PHP Newbie
โพสต์: 1
ลงทะเบียนเมื่อ: 18/07/2017 3:43 am

Re: สอนสร้าง Plugin WordPress (14) : ตัวอย่างการสร้าง Custom Taxonomy จัดการประเภท Post type

โพสต์ที่ยังไม่ได้อ่าน โดย ฮา เป็นคนไปเรื่อย »

สอบถามหน่อยครับ ถ้าเราจะสร้าง Custom Taxonomy แต่อยู่ใน Post ที่ติดมากับ wordpress โดยตรงเลยละครับ ต้องไปทำที่ไฟล์ใหนครับ
Bailey99
PHP Newbie
PHP Newbie
โพสต์: 3
ลงทะเบียนเมื่อ: 04/10/2019 1:33 pm
ที่อยู่: United States
ติดต่อ:

Re: สอนสร้าง Plugin WordPress (14) : ตัวอย่างการสร้าง Custom Taxonomy จัดการประเภท Post type

โพสต์ที่ยังไม่ได้อ่าน โดย Bailey99 »

Inquire as to whether we were to make a Custom Taxonomy, however in the post that came straightforwardly with wordpress What record do you have to do?
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 28