是否自定义分类存档页面而不是路由?

时间:2013-04-10 作者:Staple

我有一个无插件的自定义帖子类型和分类设置-见下文。我从中获得了CPT的档案,网址为:

/archives/nomination-archive
如果我使用\\u术语($post->ID,\'提名类型\',\'\'),我会在我的每个提名帖子中获得一个很好的链接,指向我的分类术语档案,即:

/archives/nomination-type/best-2013
访问此url会给我一个标题为“2013年最佳”的归档页面,但我无法让它显示任何帖子。。刷新永久链接等

非常感谢您的帮助。。。

add_action( \'init\', \'create_nomination_post_type\' );
function create_nomination_post_type() {
    register_post_type( \'nomination\',
        array(
            \'labels\' => array(
                \'name\' => __( \'Nominations\' ),
                \'singular_name\' => __( \'Nomination\' ),
                \'add_new_item\' => __( \'Add New Nomination\' )
            ),
        \'public\' => true,
        \'menu_position\' => 6,
        \'exclude_from_search\' => true,
        \'has_archive\' => true,
        \'rewrite\' => array(\'slug\' => \'nomination-archive\'),
        \'supports\' => array( 
          \'title\', 
          \'editor\',
          \'author\',
          \'thumbnail\',
          \'page-attributes\'
           ),
        )
    );
}

//
// Add nominatons type taxonomy
//
function add_nomination_type_taxonomies() {
    register_taxonomy(\'nomination_type\', \'nomination\', array(
        // Hierarchical taxonomy (like categories)
        \'hierarchical\' => true,
        \'labels\' => array(
            \'name\' => _x( \'Nomination Categories\', \'taxonomy general name\' ),
            \'singular_name\' => _x( \'Nomination Categories\', \'taxonomy singular name\' ),
            \'search_items\' =>  __( \'Search Nomination Categories\' ),
            \'all_items\' => __( \'All Nomination Categories\' ),
            \'parent_item\' => __( \'Parent Nomination Categories\' ),
            \'parent_item_colon\' => __( \'Parent Nomination Category:\' ),
            \'edit_item\' => __( \'Edit Nomination Category\' ),
            \'update_item\' => __( \'Update Nomination Category\' ),
            \'add_new_item\' => __( \'Add New Nomination Category\' ),
            \'new_item_name\' => __( \'New Nomination Category Name\' ),
            \'menu_name\' => __( \'Nomination Item Categories\' )
        ),
         //Control the slugs used for this taxonomy
        \'rewrite\' => array(
            \'slug\' => \'nomination-type\' // This controls the base slug that will display before each term
          //    \'with_front\' => true, // Don\'t display the category base before "/genres/"
            //\'hierarchical\' => false // Allows good urls
        )
    ));
}
add_action( \'init\', \'add_nomination_type_taxonomies\', 0 );

1 个回复
SO网友:Staple

我可能是个白痴——不确定。可能表明我是。

将CPT的“exclude\\u from\\u search”设置为“false”可以清除此问题。

当“exclude\\u from\\u search”(从搜索中排除\\u)为“true”时,仍然不太清楚为什么CPT归档可以工作,而分类法归档不能工作,但这就是问题所在。

结束

相关推荐

是否自定义分类存档页面而不是路由? - 小码农CODE - 行之有效找到问题解决它

是否自定义分类存档页面而不是路由?

时间:2013-04-10 作者:Staple

我有一个无插件的自定义帖子类型和分类设置-见下文。我从中获得了CPT的档案,网址为:

/archives/nomination-archive
如果我使用\\u术语($post->ID,\'提名类型\',\'\'),我会在我的每个提名帖子中获得一个很好的链接,指向我的分类术语档案,即:

/archives/nomination-type/best-2013
访问此url会给我一个标题为“2013年最佳”的归档页面,但我无法让它显示任何帖子。。刷新永久链接等

非常感谢您的帮助。。。

add_action( \'init\', \'create_nomination_post_type\' );
function create_nomination_post_type() {
    register_post_type( \'nomination\',
        array(
            \'labels\' => array(
                \'name\' => __( \'Nominations\' ),
                \'singular_name\' => __( \'Nomination\' ),
                \'add_new_item\' => __( \'Add New Nomination\' )
            ),
        \'public\' => true,
        \'menu_position\' => 6,
        \'exclude_from_search\' => true,
        \'has_archive\' => true,
        \'rewrite\' => array(\'slug\' => \'nomination-archive\'),
        \'supports\' => array( 
          \'title\', 
          \'editor\',
          \'author\',
          \'thumbnail\',
          \'page-attributes\'
           ),
        )
    );
}

//
// Add nominatons type taxonomy
//
function add_nomination_type_taxonomies() {
    register_taxonomy(\'nomination_type\', \'nomination\', array(
        // Hierarchical taxonomy (like categories)
        \'hierarchical\' => true,
        \'labels\' => array(
            \'name\' => _x( \'Nomination Categories\', \'taxonomy general name\' ),
            \'singular_name\' => _x( \'Nomination Categories\', \'taxonomy singular name\' ),
            \'search_items\' =>  __( \'Search Nomination Categories\' ),
            \'all_items\' => __( \'All Nomination Categories\' ),
            \'parent_item\' => __( \'Parent Nomination Categories\' ),
            \'parent_item_colon\' => __( \'Parent Nomination Category:\' ),
            \'edit_item\' => __( \'Edit Nomination Category\' ),
            \'update_item\' => __( \'Update Nomination Category\' ),
            \'add_new_item\' => __( \'Add New Nomination Category\' ),
            \'new_item_name\' => __( \'New Nomination Category Name\' ),
            \'menu_name\' => __( \'Nomination Item Categories\' )
        ),
         //Control the slugs used for this taxonomy
        \'rewrite\' => array(
            \'slug\' => \'nomination-type\' // This controls the base slug that will display before each term
          //    \'with_front\' => true, // Don\'t display the category base before "/genres/"
            //\'hierarchical\' => false // Allows good urls
        )
    ));
}
add_action( \'init\', \'add_nomination_type_taxonomies\', 0 );

1 个回复
SO网友:Staple

我可能是个白痴——不确定。可能表明我是。

将CPT的“exclude\\u from\\u search”设置为“false”可以清除此问题。

当“exclude\\u from\\u search”(从搜索中排除\\u)为“true”时,仍然不太清楚为什么CPT归档可以工作,而分类法归档不能工作,但这就是问题所在。

相关推荐