wordpress添加自定义内容类型

在Wordpress站点的开发过程中,wordpress默认的两种内容类型:文章、页面,可能没办法满足我们的需求,这时候我们就需要使用到自定义的内容类型了,Wordpress自定义内容类型扩展了wordpress的内容形式,让wordpress的内容不再拘泥于文章和页面,让开发人员在进行开发时更加灵活。通过下面的代码您...

在Wordpress站点的开发过程中,wordpress默认的两种内容类型:文章、页面,可能没办法满足我们的需求,这时候我们就需要使用到自定义的内容类型了,Wordpress自定义内容类型扩展了wordpress的内容形式,让wordpress的内容不再拘泥于文章和页面,让开发人员在进行开发时更加灵活。通过下面的代码您就可以创建一个自定义的内容类型了。

//添加案例自定义文章格式function media_post_type_movie() {  $labels = array(    'name'               => '案例',    'singular_name'      => '案例',    'add_new'            => '添加案例',    'add_new_item'       => '添加案例信息',    'edit_item'          => '编辑案例信息',    'new_item'           => '新案例',    'all_items'          => '所有案例',    'view_item'          => '查看案例',    'search_items'       => '搜索案例',    'not_found'          => '没找到案例资料',    'not_found_in_trash' => '回收站里没找到案例信息',     'menu_name'          => '案例'  );  $args = array(    'public'        => true,    'labels'        => $labels,    'menu_position' => 5,//    'taxonomies'    => array('category','post_tag'),    'taxonomies'    => array('post_tag'),    'supports'      => array( 'title', 'editor', 'thumbnail',  'revisions' ),    'menu_icon'     => 'dashicons-format-video',    'has_archive'   => true,    'rewrite'       => array( 'slug'  => 'media', 'with_front'  => false ),   );  register_post_type( 'media', $args );}add_action( 'init', 'media_post_type_movie' );function media_updated_messages( $messages ) {  global $post, $post_ID;  $messages['media'] = array(    0 => '',     1 => sprintf( __('案例已更新,<a href="%s">点击查看</a>'), esc_url( get_permalink($post_ID) ) ),    2 => __('自定义字段已更新。', 'iwilling'),    3 => __('自定义字段已删除。', 'iwilling'),    4 => __('案例已更新。', 'iwilling'),     5 => isset($_GET['revision']) ? sprintf( __('案例恢复到了 %s 这个修订版本。'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,    6 => sprintf( __('案例已发布,<a href="%s">点击查看</a>'), esc_url( get_permalink($post_ID) ) ),    7 => __('案例已保存', 'iwilling'),    8 => sprintf( __('案例已提交, <a target="_blank" href="%s">点击预览</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),    9 => sprintf( __('案例发布于:<strong>%1$s</strong>, <a target="_blank" href="%2$s">点击预览</a>'),      date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),    10 => sprintf( __('案例草稿已更新,<a target="_blank" href="%s">点击预览</a>', 'iwilling'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),  );  return $messages;}add_filter( 'post_updated_messages', 'media_updated_messages' );

解说:

menu_position是指内容类型在wordpress所处的位置 taxonomies是指本内容类型是不是支持默认的分类、标签等 supports本内容类型支持的内容元素:标题、编辑器、缩略图、历史版本等 menu_icon是指在后台的图标样式 has_archive是指是否有存档

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

wordpress短代码显示用户注册日期

2023-2-16 15:50:10

wordpress教程

WordPress如何添加媒体

2023-2-16 15:50:12

!
你也想出现在这里?立即 联系我们吧!
信息
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索