首页 文章

WordPress自定义帖子类型分类

提问于
浏览
0

我正在研究一种自定义的帖子类型,但我面临的问题是它需要通常的后期分类法 . 现在重写了它,但无法以正确的方式获得分类法结构 .

面包屑只显示:

Home > News > ITEM 而不是 Home > Page 1 > Archive > ITEM .

我试过这个:

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

但什么都没发生 .

2 回答

  • 0

    不确定这是你需要的还是意思,但它在这里运作良好:

    <?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' );
    
    ?>
    
  • 0

    要删除痕迹路径中的“新闻”项,您需要将其从自定义帖子类型中的重写中删除 . 试试这个=

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

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

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

相关问题