自定义帖子类型和分类插件问题

时间:2013-09-10 作者:user2567824

我正在使用WordPress中的自定义帖子类型,对Slug有一个问题。

假设我们需要创建带有分类测验类别的自定义post类型测验。我使用了以下代码:

// Create and register custom post type quiz
function create_posttype_quiz() {
    $labels = array(
        \'name\'               => _x( \'Quiz\', \'post type general name\' ),
        \'singular_name\'      => _x( \'Quiz\', \'post type singular name\' ),
        \'add_new\'            => _x( \'Add New\', \'quiz\' ),
        \'add_new_item\'       => __( \'Add New Quiz\' ),
        \'edit_item\'          => __( \'Edit Quiz\' ),
        \'new_item\'           => __( \'New Quiz\' ),
        \'all_items\'          => __( \'All Quiz\' ),
        \'view_item\'          => __( \'View Quiz\' ),
        \'search_items\'       => __( \'Search Quiz\' ),
        \'not_found\'          => __( \'No quiz found\' ),
        \'not_found_in_trash\' => __( \'No quiz found in the Trash\' ), 
        \'parent_item_colon\'  => \'\',
        \'menu_name\'          => \'Quizzes\'
    );
    $args = array(
        \'labels\'        => $labels,
        \'description\'   => \'Holds our quiz and quiz specific data\',
        \'public\'        => true,
        \'menu_position\' => 5,
        \'supports\'      => array( \'title\', \'editor\' ),
        \'has_archive\'   => true,
        \'rewrite\' => array(\'slug\' => \'quiz\'),
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,

    );

    register_post_type( \'quiz\', $args );    
}
add_action( \'init\', \'create_posttype_quiz\' );

// Create and register quiz categories
function create_taxonomies_quiz() {
    $labels = array(
        \'name\'              => _x( \'Quiz Categories\', \'taxonomy general name\' ),
        \'singular_name\'     => _x( \'Quiz Category\', \'taxonomy singular name\' ),
        \'search_items\'      => __( \'Search Quiz Categories\' ),
        \'all_items\'         => __( \'All Quiz Categories\' ),
        \'parent_item\'       => __( \'Parent Quiz Category\' ),
        \'parent_item_colon\' => __( \'Parent Quiz Category:\' ),
        \'edit_item\'         => __( \'Edit Quiz Category\' ), 
        \'update_item\'       => __( \'Update Quiz Category\' ),
        \'add_new_item\'      => __( \'Add New Quiz Category\' ),
        \'new_item_name\'     => __( \'New Quiz Category\' ),
        \'menu_name\'         => __( \'Quiz Categories\' ),
    );
    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => true,
        //\'show_admin_column\'=> true,
        \'rewrite\' => array(\'hierarchical\'=>true, \'slug\'=>\'quizzes\', \'with_front\'=>false),
    );
    register_taxonomy( \'quiz_category\', \'quiz\', $args );
}
add_action( \'init\', \'create_taxonomies_quiz\', 0 );
一切正常,我能够创建和编辑测验,将它们添加到测验类别等。此外,我还可以访问前端的测验,例如网站。com/测验/样本测验一,站点。com/测验/样本测验二。。。并在测验类别中列出测验,例如网站。com/测验/第一类,网站。com/测验/第二类。。。

问题是我不能把测验列在下面site.com/quizzes 但在site.com/quiz 相反(site.com/quizzes 将创建找不到页面错误)。

基本上,我希望能够:

访问url上的单个测验:site.com/quiz/sample-quiz-onesite.com/quizzes 而不是site.com/quiz.

1 个回复
最合适的回答,由SO网友:Rarst 整理而成

你的问题是WordPress没有对特定分类法中的所有帖子进行归档,只有对该分类法每个术语中的帖子进行归档。

在CPT注册中,您可以设置\'has_archive\' => \'quizzes\' 所以,post类型的归档段塞不同于单一段塞。然而,我不确定当您的分类法也将该段代码用于术语归档时,它是否会正常工作。

结束

相关推荐

将post-new.php?post_cat=catslug添加到管理菜单

我使使用post new成为可能。php?post\\u cat=catslug在wordpress admin中使用以下答案创建带有预填充类别的新帖子:How to add category to: 'wp-admin/post-new.php'?现在,我想在“Posts”->“Add new”管理菜单项下创建多个此格式的菜单项。因此,菜单将是:职位所有帖子新增。php?post\\u cat=profile添加新消息->发布新消息。php?post\\u cat=新闻添加新