wordpress进阶教程(一):wordpress文章类型

对于所有独立的单页面内容,例如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,下面注册的文章类型分别有:post\page\attachment\revision\nav_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中,主要内容就是“文章”-“分类”。

我们在以后的文章中再详细介绍上面注册文章类型和分类法函数的详细用法。敬请关注。

本篇教程之前的几篇教程是

本篇教程之后的几篇教程是

没有找到你要找的内容?你可以通过搜索你要找的内容,或者给我们留言。

已有5条评论

设计中心进行回复 取消回复