自定义帖子类型和分类分页 404 错误
分页在taxonomy.php 上不起作用。这是我的注册自定义帖子类型和分类法的代码
add_action('init', 'ep_add_equipment');
function ep_add_equipment()
{
$labels = array(
'name' => _x('Equipments', 'post type general name', 'epanel'),
'singular_name' => _x('Equipments', 'post type singular name', 'epanel'),
'add_new' => _x('Add New Equipment', 'slide', 'epanel'),
'add_new_item' => __('Add New Equipment', 'epanel'),
'edit_item' => __('Edit Equipment', 'epanel'),
'new_item' => __('New Equipment', 'epanel'),
'view_item' => __('View Equipments', 'epanel'),
'search_items' => __('Search Equipments', 'epanel'),
'not_found' => __('No Equipments found', 'epanel'),
'not_found_in_trash' => __('No Equipments found in Trash', 'epanel'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'products'),
'capability_type' => 'post',
'exclude_from_search' => true,
'hierarchical' => true,
'menu_icon' => get_template_directory_uri() .'/images/equipment.png',
'menu_position' => 5,
'can_export' => true,
'supports' => array('title','editor','thumbnail', 'comments','page-attributes','excerpt'/*,'author','excerpt'*/),
);
register_post_type('equipment',$args);
register_taxonomy('equipments', 'equipment', array('hierarchical' => true, 'show_in_nav_menus' => true, 'show_ui' => true,
'query_var' => true, 'labels' => array('name' => __( 'Equipments Categories' ), 'singular_label' => __('Category'), 'add_new_item' => __( 'Add New Category' ), 'search_items' => __( 'Search Categories' )), 'rewrite' => array('slug' => 'equipments')));
}
function add_menu_admin_bar() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
exit;
// $wp_admin_bar->add_menu( array( 'id' => 'theme_options', 'title' =>__( 'E-Panel', 'epanel' ), 'href' => admin_url('admin.php')."?page=epanel_settings" ) );
$wp_admin_bar->add_menu( array( 'id' => 'equipment', 'title' =>__( 'Equipments', 'epanel' ), 'href' => admin_url('edit.php')."?post_type=equipment" ) );
$wp_admin_bar->add_menu( array( 'parent' => 'equipment', 'title' =>__( 'Add New Equipment', 'epanel' ), 'href' => admin_url('post-new.php')."?post_type=equipment" ) );
$wp_admin_bar->add_menu( array( 'parent' => 'equipment', 'title' =>__( 'Equipment Categories', 'epanel' ), 'href' => admin_url('edit-tags.php')."?taxonomy=equipment_categories&post_type=equipment" ) );
}
add_action( 'admin_bar_menu', 'add_menu_admin_bar' , 70);
taxonomy.php的循环代码
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'taxonomy' => $term->taxonomy,
'term' => $term->slug,
'post_type' => 'equipment',
'paged'=> $paged,
/*'posts_per_page' => 10,*/
'caller_get_posts'=> 1
);
?>
<?php query_posts( $args ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
Pagination is not working on taxonomy.php. Here is my code for register custom post type and taxonomy
add_action('init', 'ep_add_equipment');
function ep_add_equipment()
{
$labels = array(
'name' => _x('Equipments', 'post type general name', 'epanel'),
'singular_name' => _x('Equipments', 'post type singular name', 'epanel'),
'add_new' => _x('Add New Equipment', 'slide', 'epanel'),
'add_new_item' => __('Add New Equipment', 'epanel'),
'edit_item' => __('Edit Equipment', 'epanel'),
'new_item' => __('New Equipment', 'epanel'),
'view_item' => __('View Equipments', 'epanel'),
'search_items' => __('Search Equipments', 'epanel'),
'not_found' => __('No Equipments found', 'epanel'),
'not_found_in_trash' => __('No Equipments found in Trash', 'epanel'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'products'),
'capability_type' => 'post',
'exclude_from_search' => true,
'hierarchical' => true,
'menu_icon' => get_template_directory_uri() .'/images/equipment.png',
'menu_position' => 5,
'can_export' => true,
'supports' => array('title','editor','thumbnail', 'comments','page-attributes','excerpt'/*,'author','excerpt'*/),
);
register_post_type('equipment',$args);
register_taxonomy('equipments', 'equipment', array('hierarchical' => true, 'show_in_nav_menus' => true, 'show_ui' => true,
'query_var' => true, 'labels' => array('name' => __( 'Equipments Categories' ), 'singular_label' => __('Category'), 'add_new_item' => __( 'Add New Category' ), 'search_items' => __( 'Search Categories' )), 'rewrite' => array('slug' => 'equipments')));
}
function add_menu_admin_bar() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
exit;
// $wp_admin_bar->add_menu( array( 'id' => 'theme_options', 'title' =>__( 'E-Panel', 'epanel' ), 'href' => admin_url('admin.php')."?page=epanel_settings" ) );
$wp_admin_bar->add_menu( array( 'id' => 'equipment', 'title' =>__( 'Equipments', 'epanel' ), 'href' => admin_url('edit.php')."?post_type=equipment" ) );
$wp_admin_bar->add_menu( array( 'parent' => 'equipment', 'title' =>__( 'Add New Equipment', 'epanel' ), 'href' => admin_url('post-new.php')."?post_type=equipment" ) );
$wp_admin_bar->add_menu( array( 'parent' => 'equipment', 'title' =>__( 'Equipment Categories', 'epanel' ), 'href' => admin_url('edit-tags.php')."?taxonomy=equipment_categories&post_type=equipment" ) );
}
add_action( 'admin_bar_menu', 'add_menu_admin_bar' , 70);
Loop code for taxonomy.php
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'taxonomy' => $term->taxonomy,
'term' => $term->slug,
'post_type' => 'equipment',
'paged'=> $paged,
/*'posts_per_page' => 10,*/
'caller_get_posts'=> 1
);
?>
<?php query_posts( $args ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能您需要启用搜索才能启用分页
在声明自定义分类法时,您应该禁用搜索排除。
这解决了我的问题。我很难找到这个解决方案。希望这对大家有帮助。
我的代码是:
May be you need to enable search to enable pagination
While declaring custom taxonomy you should disable search excluding.
This fixed my problem. I have very hard time to find this solution. Hope this helps everyone.
My code is: