【发布时间】:2014-05-14 09:45:59
【问题描述】:
所以我正在尝试在 Wordpress 中设置一个具有以下永久链接结构的网站:
http://www.site.com/trades/trade-type
我希望交易成为一个实际页面,并且我创建了交易类型作为自定义帖子类型。
在我的交易类型自定义帖子类型中,我将 slug 设置为“交易”以使用该永久链接作为我的基本结构。所以我在自定义帖子类型下创建的所有帖子都应该继续 /trades URL。
当我设置这个 slug 时,我能够成功地保存和查看 /trades/trade-type 页面上的页面。但是当我尝试转到 /trades 页面时,它就崩溃了。
当我将自定义帖子类型中的 slug 更改为“trades2”时,我能够成功查看 /trades 页面,但是我创建的所有交易类型现在都在 trades2/trade-type 下。
/trades 页面和自定义帖子类型 slug 之间似乎存在某种冲突。有没有办法可以编辑 functions.php 来适应两者?任何帮助将不胜感激。
下面是我的交易类型自定义帖子类型的functions.php
//Register Custom Trades Post Type
function custom_trades() {
$labels = array(
'name' => _x( 'Trades', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Trade', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Trades', 'text_domain' ),
'parent_item_colon' => __( 'Parent Trade:', 'text_domain' ),
'all_items' => __( 'All Trades', 'text_domain' ),
'view_item' => __( 'View Trade', 'text_domain' ),
'add_new_item' => __( 'Add New Trade', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'edit_item' => __( 'Edit Trade', 'text_domain' ),
'update_item' => __( 'Update Trade', 'text_domain' ),
'search_items' => __( 'Search Trade', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
);
$rewrite = array(
'slug' => 'trades',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'ds_trades', 'text_domain' ),
'description' => __( 'Post Type Description', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'page-attributes', ),
'taxonomies' => array( 'category' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-generic',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'ds_trades', $args );
}
// Hook into the 'init' action
add_action( 'init', 'custom_trades', 0 );
【问题讨论】: