首页 > 解决方案 > 在archive.php中显示分类

问题描述

我用一个名为 的自定义分类法制作了一个 cpt tipos_productos,我试图将分类法显示为一个archive.phpcalled archive-products.php,但我得到了一个404 error. 这是我的cpt代码。

功能 ct_tipos_productos() {

$labels = array(
    'name'                       => _x( 'Tipos de Productos', 'Taxonomy General Name', 'bonestheme' ),
    'singular_name'              => _x( 'Tipo de Producto', 'Taxonomy Singular Name', 'bonestheme' ),
    'menu_name'                  => __( 'Tipos de Productos', 'bonestheme' ),
    'all_items'                  => __( 'All Items', 'bonestheme' ),
    'parent_item'                => __( 'Parent Item', 'bonestheme' ),
    'parent_item_colon'          => __( 'Parent Item:', 'bonestheme' ),
    'new_item_name'              => __( 'New Item Name', 'bonestheme' ),
    'add_new_item'               => __( 'Add New Item', 'bonestheme' ),
    'edit_item'                  => __( 'Edit Item', 'bonestheme' ),
    'update_item'                => __( 'Update Item', 'bonestheme' ),
    'view_item'                  => __( 'View Item', 'bonestheme' ),
    'separate_items_with_commas' => __( 'Separate items with commas', 'bonestheme' ),
    'add_or_remove_items'        => __( 'Add or remove items', 'bonestheme' ),
    'choose_from_most_used'      => __( 'Choose from the most used', 'bonestheme' ),
    'popular_items'              => __( 'Popular Items', 'bonestheme' ),
    'search_items'               => __( 'Search Items', 'bonestheme' ),
    'not_found'                  => __( 'Not Found', 'bonestheme' ),
    'no_terms'                   => __( 'No items', 'bonestheme' ),
    'items_list'                 => __( 'Items list', 'bonestheme' ),
    'items_list_navigation'      => __( 'Items list navigation', 'bonestheme' ),
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => false,
);
register_taxonomy( 'tipos_productos', array( 'producto' ), $args );

}
add_action( 'init', 'ct_tipos_productos', 0 );

ps:我得到了一些使用该分类法创建的产品:

标签: phpwordpress

解决方案


帖子类型 = 产品

分类法 = tipos_productos

您可能需要根据上述代码中的分类将存档文件名更改为archive-tipos_productos.php。

这就是您的文件应该命名的名称。分类-{分类}.php

有关更多详细信息,您可以访问此 URL https://developer.wordpress.org/themes/template-files-section/taxonomy-templates/

如果要使用archive.php 文件,需要在archive.php 中添加以下代码

 // Your Taxonomy Result will show inside this condition.
 if( is_tax('tipos_productos') ){

 }

推荐阅读