dd

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


对于所有独立的单页面内容,例如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' ),        ) );   register_taxonomy( 'category', 'post', array(            'hierarchical' => true,            'query_var' => 'category_name',            'rewrite' => $rewrite['category'],            'public' => true,            'show_ui' => true,            '_builtin' => true,        ) );  

这是注册wordpress的文章、也就是post,下面注册的文章类型分别有:post\page\attachment\revision\nav_menu_item,分别为:文章、页面、附件、修订版、菜单项。它们在数据表中也都存储在post表中,用一个post_type属性哎区分。
我们也可以使用这个函数注册一个新的表现形式的文章类型。
在CMS系统中,有了文章,还得有将文章归档、分类。
wordpress系统自带的分类法为:分类目录、标签。
注意,在wordpress中标签也是一种独立的分类法,跟分类目录可以等同。
与文章类型一样,wordpress使用函数register_taxonomy来注册分类方法。打开你的wp-includes文件夹下面的taxonomy.php文件,也在第一个函数中,

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' ),        ) );   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中,主要内容就是“文章”-“分类”。

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