我有一个包含两种自定义帖子类型、布道和成员的主题。我也将永久链接设置为 postname。
起初,single.php 会捕获一般的博客文章以及成员,但不会捕获布道……它只会显示 index.php 文件。
经过一番研究,我发现重置(保存)永久链接会重置它们。这种工作现在可以捕获成员自定义帖子,但仅显示 index.php 用于布道。
我就是这样称呼他们的……
// Custom Post types for Sermons
add_action('init', 'sermons');
function sermons() {
$args = array(
'labels' => array(
'name' => __( 'Sermons' ),
'singular_name' => __( 'Sermons' ),
'add_new' => __( 'Add Sermon' ),
'add_new_item' => __( 'Add Sermon' ),
'edit_item' => __( 'Edit Sermon' ),
'new_item' => __( 'Add Sermon' ),
'view_item' => __( 'View Sermon' ),
'search_items' => __( 'Search Sermons' ),
'not_found' => __( 'No Home Sermons found' ),
'not_found_in_trash' => __( 'No Sermons found in trash' )
),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
// 'menu_icon' => WP_CONTENT_URL . '/themes/####/images/home-widget.png',
'rewrite' => true,
'exclude_from_search' => true,
'menu_position' => 20,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'has_archive' => true
);
register_post_type('sermons',$args);
}
// Custom Post types for Members
add_action('init', 'members');
function members() {
$args = array(
'labels' => array(
'name' => __( 'Members' ),
'singular_name' => __( 'Members' ),
'add_new' => __( 'Add Member' ),
'add_new_item' => __( 'Add Member' ),
'edit_item' => __( 'Edit Member' ),
'new_item' => __( 'Add Member' ),
'view_item' => __( 'View Member' ),
'search_items' => __( 'Search Members' ),
'not_found' => __( 'No Home Members found' ),
'not_found_in_trash' => __( 'No Members found in trash' )
),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
// 'menu_icon' => WP_CONTENT_URL . '/themes/####/images/home-widget.png',
'rewrite' => true,
'exclude_from_search' => true,
'menu_position' => 20,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'has_archive' => true
);
register_post_type('members',$args);
}
我试过single-sermons.php 和single-members.php,似乎都不管用。是我注册每种自定义帖子类型的方式破坏了这一点吗?
**** 编辑 ****'rewrite' => true
从 $args 中删除,一切都很好,但我更希望有 SEO 友好的网址。
**** 编辑 **** 修复它......显然,删除'rewrite' => true
参数,刷新永久链接,然后'rewrite' => true
再次添加,就可以了。