對於所有獨立的單頁面內容,例如 WordPress 的文章、頁面。它們都屬於 WordPress 的一種類型的文章。
WordPress「註冊」 一種新的文章類型使用的函數是:register_post_type(),打開你的 WordPress 的 include 文件夾下面的 post.php 文件。看第一個函數 create_initial_post_types,裏面調用了幾次 register_post_type 函數,例如:

  1. register_post_type( 'post', array(   
  2.         'labels' => array(   
  3.             'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),   
  4.         ),   
  5.         'public'  => true,   
  6.         '_builtin' => true, /* internal use only. don't use this when registering your own post type. */  
  7.         '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */  
  8.         'capability_type' => 'post',   
  9.         'map_meta_cap' => true,   
  10.         'hierarchical' => false,   
  11.         'rewrite' => false,   
  12.         'query_var' => false,   
  13.         'delete_with_user' => true,   
  14.         'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),   
  15.     ) );  

這是註冊 WordPress 的文章、也就是 post,下面註冊的文章類型分別有:postpageattachment
evision
av_menu_item,分別為:文章、頁面、附件、修訂版、菜單項。它們在數據表中也都存儲在 post 表中,用一個 post_type 屬性哎區分。
我們也可以使用這個函數註冊一個新的表現形式的文章類型。
在 CMS 系統中,有了文章,還得有將文章歸檔、分類。
WordPress 系統自帶的分類法為:分類目錄、標籤。
注意,在 WordPress 中標籤也是一種獨立的分類法,跟分類目錄可以等同。
與文章類型一樣,WordPress 使用函數 register_taxonomy 來註冊分類方法。打開你的 wp-includes 文件夾下面的 taxonomy.php 文件,也在第一個函數中,

  1. register_taxonomy( 'category', 'post', array(   
  2.         'hierarchical' => true,   
  3.         'query_var' => 'category_name',   
  4.         'rewrite' => $rewrite['category'],   
  5.         'public' => true,   
  6.         'show_ui' => true,   
  7.         '_builtin' => true,   
  8.     ) );  

上面代碼是註冊 WordPress 默認的分類方法:分類-category 。後面還依次添加了分類法:標籤-post_tag 、菜單-nav_menu 、鏈接分類-link_category 、文章形式-post_format 。

我想在 cms 中,主要內容就是 「文章」-「分類」 。

我們在以後的文章中再詳細介紹上面註冊文章類型和分類法函數的詳細用法。敬請關注。