簡體   English   中英

如何在WordPress及其類別中創建具有類別的自定義帖子類型?

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

如何在WordPress中使用其類別創建自定義帖子類型

我想在我的網站中創建一個新聞欄目(與帖子相同),但是我想創建自己的新聞欄目,其帖子類型為新聞。 請提出建議。

嘗試這個 :

<?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