Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2537445
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: 系统运维

2012-04-26 12:39:35

我们知道wordpress中,文章,媒体,页面都是存放在wp_posts表中的。它们都被定义为一种post类型。wordpress提供了钩子让我们自己注册新的POST类型。下面我们注册一种新的类型“文档”。

点击(此处)折叠或打开

  1. /**
  2.  * an example of registering a post type called "document" including providing contextual help
  3.  */
  4. add_action('init', 'codex_custom_init');
  5. function codex_custom_init() {
  6.     $labels = array (
  7.         'name' => _x('文档',
  8.         'post type general name'
  9.     ), 'singular_name' => _x('文档', 'post type singular name'), 'add_new' => _x('添加', 'document'), 'add_new_item' => __('添加文档'), 'edit_item' => __('编辑文档'), 'new_item' => __('新建'), 'all_items' => __('所有文档'), 'view_item' => __('查看文档'), 'search_items' => __('搜索文档'), 'not_found' => __('没有找到文档'), 'not_found_in_trash' => __('回收站中没有找到文档'), 'parent_item_colon' => '', 'menu_name' => '文档');
  10.     $args = array (
  11.         'labels' => $labels,
  12.         'public' => true,
  13.         'publicly_queryable' => true,
  14.         'show_ui' => true,
  15.         'show_in_menu' => true,
  16.         'query_var' => true,
  17.         'rewrite' => true,
  18.         'capability_type' => 'post',
  19.         'has_archive' => true,
  20.         'hierarchical' => false,
  21.         'menu_position' => null,
  22.         'supports' => array (
  23.             'title',
  24.             'editor',
  25.             'author',
  26.             'thumbnail',
  27.             'excerpt',
  28.             'comments'
  29.         ),
  30.         'taxonomies' => array (
  31.             'category',
  32.             'post_tag'
  33.             ) // this is IMPORTANT
  34.  
  35.     );
  36.     register_post_type('document', $args);
  37. }
将上面的代码添加到functions.php中,然后在后台就会看到我们新注册的文档类型。
上面的代码调用了一个register_post_type('document', $args);函数,它会注册一种新的post类型。


阅读(1899) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~