【温馨提示:视频教程将在6月份开始更新,可提前购买,1-10元一节课,联系QQ248758228】
wordpress默认只有一个文章,一般情况可以通过分类来区别文章和使用不同的模板,但是为了更方便管理,一般情况我们是添加自定义类型的文章。下面直接上代码:
//新增自定义文章类型:作品 function ws_work() { register_post_type( 'work', //这里的work可以自行修改,主要体现在URL里面 array( 'labels' => array( 'name' => '作品', 'singular_name' => '所有作品', 'add_new' => '添加作品', 'add_new_item' => '添加新作品', 'edit' => '编辑', 'edit_item' => '编辑作品', 'new_item' => '新作品', 'view' => '查看作品', 'view_item' => '查看作品', 'search_items' => '搜索作品', 'not_found' => '没有找到相关作品', 'not_found_in_trash' => '没有作品评论', 'parent' => '作品评论', ), 'exclude_from_search'=>false, 'public' => true, 'menu_position' => 6, 'supports' => array( 'title', 'editor','comments', 'custom-fields','thumbnail','excerpt'), //为自定义文章添加标题,编辑器,评论,自定义字段,特色图像,摘要功能 'taxonomies' => array( '' ), //分类法,我们是单独定义 'has_archive' => true, 'taxonomies'=> array('post_tag'), //没有这一句是没有标签功能的 ) ); } add_action( 'init', 'ws_work' ); //挂载函数 //为商品类自定义类型增加分类功能 add_action( 'init', 'ws_works', 0 ); function ws_works() { register_taxonomy( 'works', //这个分类法 'work', //这个是自定义文章类型,默认文章是post,其他是你自己定义的 array( 'labels' => array( 'name' => '作品分类', 'add_new_item' => '添加作品', 'new_item_name' => "新作品分类" ), 'show_ui' => true, 'show_tagcloud' => true, 'hierarchical' => true, ) ); }
有了上面的内容,你的博客后台就会出现新的文章类型了。如下图:
就是这么简单。当然还有其他问题。比如说自定义文章类型的伪静态怎么操作?我们将在以后慢慢讲解。
0个问题