我創建了 Cutom 帖子型別并創建了自定義分類但是當我嘗試查看任何類別時頁面顯示 index.php insted of taxanomy.php 我也嘗試了 taxonomy-portfolio-category.php 但它仍然顯示 index.php
投資組合帖子型別是使用以下代碼創建的:
`
// portfolio Custom Post Type
function portfolio_init()
{
// set up portfolio labels
$labels = array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio',
'add_new' => 'Add New Portfolio',
'add_new_item' => 'Add New Portfolio',
'edit_item' => 'Edit Portfolio',
'new_item' => 'New Portfolio',
'all_items' => 'All Portfolio',
'view_item' => 'View Portfolio',
'search_items' => 'Search Portfolio',
'not_found' => 'No Portfolio Found',
'not_found_in_trash' => 'No Portfolio found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Portfolio',
);
// register post type
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
"publicly_queryable" => true,
"hierarchical" => false,
'rewrite' => array('slug' => 'portfolio', 'with_front' => false),
'query_var' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'menu_icon' => 'dashicons-layout',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'
)
);
flush_rewrite_rules();
register_post_type('portfolio', $args);
// register taxonomy
register_taxonomy('portfolio-category', 'portfolio', array(
'
hierarchical' => true,
'label' => 'Portfolio Category',
'query_var' => true,
'rewrite' => array('slug' => 'portfolio', 'with_front' => false),
));
//register tags
register_taxonomy('portfolio_tag', 'portfolio', array(
'hierarchical' => false,
'label' => 'Portfolio Tags',
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array('slug' => 'portfolio', 'with_front' => false),
));
flush_rewrite_rules();
}
add_action('init', 'portfolio_init');
`
我期待 taxonomy-portfolio-category.php 不是 index.php
uj5u.com熱心網友回復:
您可以在注冊分類時嘗試修改重寫規則。目前所有三個;帖子型別和兩個分類法共享相同的重寫規則。它們都指向相同的重寫結構,其中帖子型別贏得了比賽,即 index.php。
分類法的新重寫規則:
// register taxonomy
register_taxonomy(
'portfolio-category',
'portfolio',
array(
'hierarchical' => true,
'label' => 'Portfolio Category',
'query_var' => true,
'rewrite' => array(
'slug' => 'portfolio-category',
'with_front' => false,
),
)
);
//register tags
register_taxonomy(
'portfolio_tag',
'portfolio',
array(
'hierarchical' => false,
'label' => 'Portfolio Tags',
'query_var' => true,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'rewrite' => array(
'slug' => 'portfolio-tag',
'with_front' => false,
),
)
);
如果您需要進一步自定義分類資訊,例如。Portfolio/category/post_name,您必須使用add_rewrite_rule()、add_rewrite_tag()和其他一些函式創建自定義重寫規則:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/519455.html
上一篇:@foreachphp串列物件
