您好,WP StackExchange,
我拿起它,它处理定制的Post-Type归档。
所以我们有一个叫做资源的CPT。在资源下,我们有一个称为资源类型的自定义分类法。对于资源类型,我们有媒体、画廊、博客和常见问题解答。
所以每个人都有自己的permalink:
/资源/媒体/
/资源/博客/
等
你可能想知道,为什么要把博客文章放在参考资料下,这是一个好问题,基于最近的开发人员笔记,而营销团队想要的是,他们希望博客具有永久链接结构。使用常规贴子类型时,在贴子的永久链接设置中添加基时会出现一些冲突问题。2-3个其他开发人员已经接触到了这一点,我希望我能完成它。这条路线不是我所知道的最好的路线,但它是我正在使用的:/感谢您的帮助。
我想修复的是博客的档案。所以如果我们点击/resources/blog/2012/02,我们会得到一个404。我一直在寻找,但找不到一种方法来实现这一目标,也找不到是否可以为我指明正确的方向。我尝试了一些归档模板,但似乎什么都不适合我。
还有一些快速的背景故事,我们在帖子和资源下有重复的帖子。因此,如果你点击/2012/02,你会从帖子中获得反馈。我们将删除帖子下的帖子,这样资源将是博客的唯一方法。
编辑:CPT和分类的代码
// Resource
function cpt_pt_resources() {
$labels = array(
    \'name\'                  => _x( \'Resources\', \'Post Type General Name\', \'text_domain\' ),
    \'singular_name\'         => _x( \'Resource\', \'Post Type Singular Name\', \'text_domain\' ),
    \'menu_name\'             => __( \'Resources\', \'text_domain\' ),
    \'name_admin_bar\'        => __( \'Resources\', \'text_domain\' ),
    \'archives\'              => __( \'Resource Archives\', \'text_domain\' ),
    \'attributes\'            => __( \'Resource Attributes\', \'text_domain\' ),
    \'parent_item_colon\'     => __( \'Parent Item:\', \'text_domain\' ),
    \'all_items\'             => __( \'All Items\', \'text_domain\' ),
    \'add_new_item\'          => __( \'Add New Resource\', \'text_domain\' ),
    \'add_new\'               => __( \'Add Resource\', \'text_domain\' ),
    \'new_item\'              => __( \'New Item\', \'text_domain\' ),
    \'edit_item\'             => __( \'Edit Item\', \'text_domain\' ),
    \'update_item\'           => __( \'Update Item\', \'text_domain\' ),
    \'view_item\'             => __( \'View Item\', \'text_domain\' ),
    \'view_items\'            => __( \'View Items\', \'text_domain\' ),
    \'search_items\'          => __( \'Search Item\', \'text_domain\' ),
    \'not_found\'             => __( \'Not found\', \'text_domain\' ),
    \'not_found_in_trash\'    => __( \'Not found in Trash\', \'text_domain\' ),
    \'featured_image\'        => __( \'Featured Image\', \'text_domain\' ),
    \'set_featured_image\'    => __( \'Set featured image\', \'text_domain\' ),
    \'remove_featured_image\' => __( \'Remove featured image\', \'text_domain\' ),
    \'use_featured_image\'    => __( \'Use as featured image\', \'text_domain\' ),
    \'insert_into_item\'      => __( \'Insert into item\', \'text_domain\' ),
    \'uploaded_to_this_item\' => __( \'Uploaded to this item\', \'text_domain\' ),
    \'items_list\'            => __( \'Items list\', \'text_domain\' ),
    \'items_list_navigation\' => __( \'Items list navigation\', \'text_domain\' ),
    \'filter_items_list\'     => __( \'Filter items list\', \'text_domain\' ),
);
$args = array(
    \'label\'                 => __( \'Resource\', \'text_domain\' ),
    \'description\'           => __( \'Resources\', \'text_domain\' ),
    \'labels\'                => $labels,
    \'supports\'              => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\', \'revisions\', \'page-attributes\', \'post-formats\', \'custom-fields\', ),
    \'taxonomies\'            => array( \'category\', \'post_tag\', ),
    \'hierarchical\'          => true,
    \'public\'                => true,
    \'show_ui\'               => true,
    \'show_in_menu\'          => true,
    \'menu_position\'         => 5,
    \'menu_icon\'             => \'dashicons-index-card\',
    \'show_in_admin_bar\'     => false,
    \'show_in_nav_menus\'     => true,
    \'can_export\'            => true,
    \'has_archive\'           => true,        
    \'exclude_from_search\'   => false,
    \'publicly_queryable\'    => true,
    \'capability_type\'       => \'page\',
    \'rewrite\'               => array( \'slug\' => \'resources/%resource-type%\', \'with_front\' => false ),
);
register_post_type( \'resource\', $args );
}
add_action( \'init\', \'cpt_pt_resources\', 0 );
// Resource URL rewrite
function res_post_link( $post_link, $id = 0 ){
$post = get_post($id);  
if ( is_object( $post ) ){
    $terms = wp_get_object_terms( $post->ID, \'resource-type\' );
    if( $terms ){
        return str_replace( \'%resource-type%\' , $terms[0]->slug , $post_link );
    }
}
return $post_link;  
}
add_filter( \'post_type_link\', \'res_post_link\', 1, 3 );
// Custom taxonomy Resource Type
function cpt_pt_resource_tax() {
$labels = array(
    \'name\'              => _x( \'Resource Types\', \'taxonomy general name\', \'textdomain\' ),
    \'singular_name\'     => _x( \'Resource Type\', \'taxonomy singular name\', \'textdomain\' ),
    \'menu_name\'         => __( \'Resource Types\', \'textdomain\' ),
    \'search_items\'      => __( \'Search Resource Types\', \'textdomain\' ),
    \'all_items\'         => __( \'All Resource Types\', \'textdomain\' ),
    \'parent_item\'       => __( \'Parent Resource Type\', \'textdomain\' ),
    \'parent_item_colon\' => __( \'Parent Resource Type:\', \'textdomain\' ),
    \'edit_item\'         => __( \'Edit Resource Type\', \'textdomain\' ),
    \'update_item\'       => __( \'Update Resource Type\', \'textdomain\' ),
    \'add_new_item\'      => __( \'Add New Resource Type\', \'textdomain\' ),
    \'new_item_name\'     => __( \'New Resource Type Name\', \'textdomain\' ),    
);
$args = array(
    \'hierarchical\'      => true,
    \'labels\'            => $labels,
    \'show_ui\'           => true,
    \'show_admin_column\' => true,
    \'query_var\'         => true,
    \'menu_position\'     => 0,
    \'rewrite\'           => array( \'slug\' => \'resources\', \'with_front\' => false ),
);
register_taxonomy( \'resource-type\', array( \'resource\' ),  $args );
}
add_action( \'init\', \'cpt_pt_resource_tax\', 0 );
// Custom URL for FAQs
function faq_post_link( $post_link, $id = 0 ){
$post = get_post($id);  
if ( is_tax( \'resource-type\', \'faq\') ){
    $terms = wp_get_object_terms( $post->ID, \'faqs\' );
    if( $terms ){
        return str_replace( \'%resource-type%\' , $terms[0]->slug , $post_link );
    }
}
    return $post_link;  
}
add_filter( \'post_type_link\', \'faq_post_link\', 1, 3 );