繁体   English   中英

WordPress自定义帖子类型分类

[英]WordPress Custom Post Type taxonomy

我正在处理自定义帖子类型,但是我面临的问题是它需要常规的帖子分类法。 现在对其进行了重写,但是无法以正确的方式获得分类结构。

面包屑仅显示:

主页>新闻> ITEM,而不是Home>页面1>存档> ITEM

我尝试了这个:

'taxonomies' => array( 'Page 1', 'Archive' ),

但是什么也没发生。

不确定这是否是您的需要或意思,但是在这里效果很好:

<?php
/*
Plugin Name: Page 1 Post Type
Plugin URI: 
Author: 
Author URI: 
Version: 0.1
Description: 
License: GPL2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

function codex_custom_init() {
  $labels = array(
    'name' => 'Page 1s',
    'singular_name' => 'Page 1',
    'add_new' => 'Add New',
    'add_new_item' => 'Add New Page 1',
    'edit_item' => 'Edit Page 1',
    'new_item' => 'New Page 1',
    'all_items' => 'All Page 1s',
    'view_item' => 'View Page 1',
    'search_items' => 'Search Page 1s',
    'not_found' =>  'No Page 1s found',
    'not_found_in_trash' => 'No Page 1s found in Trash', 
    'parent_item_colon' => '',
    'menu_name' => 'Page 1s'
  );

  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array( 'slug' => 'Page1' ),
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => true,
    'menu_position' => null,
    'supports' => array('title', 'editor', 'revisions', 'page-attributes' )
  ); 

  register_post_type( 'Page 1', $args );
}
add_action( 'init', 'codex_custom_init' );

?>

为了删除痕迹中的“新闻”项,您需要从自定义帖子类型的重写中删除该项。 试试这个=

'rewrite' => array('slug' => 'Page1', 'with_front' => false),

顾名思义,每次创建新的自定义帖子类型时,它都会将其创建为帖子,并且默认情况下,WordPress网站中的所有帖子都列在博客/新闻页面下,因此为什么它们会出现在您的面包屑中。

这可能无法完全解决您的问题,因为我认为您也需要对面包屑进行一些格式化-这是用于面包屑管理的好插件,并且还提供了许多可自定义的设置! = http://wordpress.org/plugins/breadcrumb-navxt/

暂无
暂无

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

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