對於所有獨立的單頁面內容,例如 WordPress 的文章、頁面。它們都屬於 WordPress 的一種型別的文章。
WordPress「註冊」 一種新的文章型別使用的函式是:register_post_type(),開啟你的 WordPress 的 include 資料夾下面的 post.php 檔案。看第一個函式 create_initial_post_types,裡面呼叫了幾次 register_post_type 函式,例如:
- register_post_type( 'post', array(
- 'labels' => array(
- 'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
- ),
- 'public' => true,
- '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
- '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
- 'capability_type' => 'post',
- 'map_meta_cap' => true,
- 'hierarchical' => false,
- 'rewrite' => false,
- 'query_var' => false,
- 'delete_with_user' => true,
- 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
- ) );
這是註冊 WordPress 的文章、也就是 post,下面註冊的文章型別分別有:postpageattachment
evision
av_menu_item,分別為:文章、頁面、附件、修訂版、選單項。它們在資料表中也都儲存在 post 表中,用一個 post_type 屬性哎區分。
我們也可以使用這個函式註冊一個新的表現形式的文章型別。
在 CMS 系統中,有了文章,還得有將文章歸檔、分類。
WordPress 系統自帶的分類法為:分類目錄、標籤。
注意,在 WordPress 中標籤也是一種獨立的分類法,跟分類目錄可以等同。
與文章型別一樣,WordPress 使用函式 register_taxonomy 來註冊分類方法。開啟你的 wp-includes 資料夾下面的 taxonomy.php 檔案,也在第一個函式中,
- register_taxonomy( 'category', 'post', array(
- 'hierarchical' => true,
- 'query_var' => 'category_name',
- 'rewrite' => $rewrite['category'],
- 'public' => true,
- 'show_ui' => true,
- '_builtin' => true,
- ) );
上面程式碼是註冊 WordPress 預設的分類方法:分類-category 。後面還依次新增了分類法:標籤-post_tag 、選單-nav_menu 、連結分類-link_category 、文章形式-post_format 。
我想在 cms 中,主要內容就是 「文章」-「分類」 。
我們在以後的文章中再詳細介紹上面註冊文章型別和分類法函式的詳細用法。敬請關注。