php - 在archive.php中显示分类
问题描述
我用一个名为 的自定义分类法制作了一个 cpt tipos_productos
,我试图将分类法显示为一个archive.php
called 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:我得到了一些使用该分类法创建的产品:
解决方案
帖子类型 = 产品
分类法 = 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') ){
}
推荐阅读
- ide - 在哪里使用 Nim (linux) 编程?
- javascript - JavaScript 函数将打开 div 标签;然而,第二个 JavaScript 函数不会关闭它
- r - 如何计算r中一组中一个值与所有其他值之间的平均差异
- jquery - 将动态href url更改为jquery中的另一个值
- r - 在 dplyr mutate 中返回多列
- android - 默认 FirebaseApp 未在此进程 com.myapp 中初始化。确保首先调用 FirebaseApp.initializeApp(Context)
- jquery - Wordpress Ajax POST 错误 403 admin-ajax.php
- javascript - 当输入中有文本时,如何切换元素上的类?
- javascript - 如何删除字符串末尾的反斜杠?
- javascript - 如何使用 php 和 html 使表格条目可点击?