加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

wordpress添加自定义内容类型

发布时间:2020-12-14 14:43:21 所属栏目:wordpress 来源:网络整理
导读:在Wordpress站点的开发过程中,wordpress默认的两种内容类型:文章、页面,可能没办法满足我们的需求,这时候我们就需要使用到自定义的内容类型了,Wordpress自定义内容类型扩展了wordpress的内容形式,让wordpress的内容不再拘泥于文章和页面,让开发人员在

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

 '案例','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( __('案例已更新,'),esc_url( get_permalink($post_ID) ) ),2 => __('自定义字段已更新。','iwilling'),3 => __('自定义字段已删除。',4 => __('案例已更新。',5 => isset($_GET['revision']) ? sprintf( __('案例恢复到了 %s 这个修订版本。'),wp_post_revision_title( (int) $_GET['revision'],false ) ) : false,6 => sprintf( __('案例已发布,'),7 => __('案例已保存',8 => sprintf( __('案例已提交, '),esc_url( add_query_arg( 'preview','true',get_permalink($post_ID) ) ) ),9 => sprintf( __('案例发布于:%1$s, '),date_i18n( __( 'M j,Y @ G:i' ),strtotime( $post->post_date ) ),10 => sprintf( __('案例草稿已更新,',);
  return $messages;
}
add_filter( 'post_updated_messages','media_updated_messages' );

解说:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读