我创建了自定义分类法,并使用以下代码将其注册到“页面”
//hook into the init action and call create_book_taxonomies when it fires
add_action( \'init\', \'create_Offer_Categorys_hierarchical_taxonomy\', 0 );
//create a custom taxonomy name it Offer Categorys for your posts
function create_Offer_Categorys_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
\'name\' => _x( \'Offer Category\', \'offer Categories general name\' ),
\'singular_name\' => _x( \'Offer Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Offer Category\' ),
\'all_items\' => __( \'All Offer Categorys\' ),
\'parent_item\' => __( \'Parent Offer Category\' ),
\'parent_item_colon\' => __( \'Parent Offer Category:\' ),
\'edit_item\' => __( \'Edit Offer Category\' ),
\'update_item\' => __( \'Update Offer Category\' ),
\'add_new_item\' => __( \'Add New Offer Category\' ),
\'new_item_name\' => __( \'New Offer Category Name\' ),
\'menu_name\' => __( \'Offer Category\' ),
);
// Now register the taxonomy
register_taxonomy(\'offer-category\',array(\'page\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'exclude_from_search\' => false,
\'rewrite\' => array( \'slug\' => \'offer-category\' ),
));
}
然后我创建了一个名为
taxonomy-offer-category.php 问题是分页无法正常工作。编写分页代码后,分页url如下所示\'/offer-category/automobile/page/2\', 等
但是这个页面给出了错误(404),但是当我手动点击url时
/offer-category/automobile?page=2 然后给出结果。我不知道是什么问题。以下是分页代码
$term_id=get_queried_object()->term_id;
$paged = (get_query_var(\'page\')) ? get_query_var(\'page\') : 1;
// echo $paged;
$args = array(
\'post_type\' => \'page\',
\'paged\' => $paged,
\'posts_per_page\' => \'1\',
\'tax_query\' => array(
array( \'taxonomy\' => \'offer-category\',
\'field\' => \'id\',
\'terms\' => $term_id
)
),
);
wp_reset_query();
//$page_args=array(\'post_type\' => \'page\');
$query = new WP_Query($args);
$big = 999999999; // need an unlikely integer
$links = paginate_links( array(
\'current\' => max( 1, get_query_var(\'page\') ),
\'total\' => $query->max_num_pages,
\'prev_text\' => \'<\',
\'next_text\' => \'>\',
\'type\' => \'array\'
) );
我已经尝试了谷歌所有可能的答案,比如使用格式,使用页面代替页面等,这个问题是很久以前的问题了,我不知道它是否已经修复。你们能帮我一下吗。
谢谢