简体   繁体   English

如何在WordPress及其类别中创建具有类别的自定义帖子类型?

[英]How to create custom post types with categories in wordpress with its category?

How to create custom post types in wordpress with its category 如何在WordPress中使用其类别创建自定义帖子类型

I want to create a news section in my site (same as posts), but i want to create my own news section having post type as news. 我想在我的网站中创建一个新闻栏目(与帖子相同),但是我想创建自己的新闻栏目,其帖子类型为新闻。 Please make suggestion. 请提出建议。

try this : 尝试这个 :

<?php
add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'news',
    array(
      'labels' => array(
        'name' => __( 'News' ),
        'singular_name' => __( 'News' )
      ),
      'capability_type' =>  'post',
      'public' => true,
      'supports' => array(
      'title',
      'editor',
      'excerpt',
      'trackbacks',
      'custom-fields',
      'revisions',
      'thumbnail',
      'author',
      'page-attributes',
      )
    )
  );
}
register_taxonomy( 'news_category', 'news',array('label' => __( 'Categories' ),'rewrite' => array( 'slug' => 'news_category' ),'hierarchical' => true, ) );
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM