我插入了一个taxonomy.php文件,其中包含用于从自定义帖子类型中获取图像的类别和子类别的代码,如下所示:
自定义帖子类型:-
function custom_gallery_images(){
$labels = array(
'name' =>_x('Gallery','Post Type General Name', 'Avada'),
'singular_name' =>_x('Gallery','Post Type Singular Name','Avada'),
'Menu_name' =>__('Gallery','Avada'),
'Menu_name' =>__('Gallery','Avada'),
'parent_item_colon' =>__('Parent Gallery','Avada'),
'all_items' =>__('All Gallery','Avada'),
'view_item' =>__('View Gallery','Avada'),
'add_new_item' =>__('Add New Gallery','Avada'),
'add_new' =>__('Add New','Avada'),
'edit_item' =>__('Edit Gallery','Avada'),
'update_item' =>__('Update Gallery', 'Avada'),
'search_items' =>__('Search Gallery','Avada'),
'not_found' =>__('Not Found','Avada'),
'not_found_in_trash'=>__('Not Found In Trash','Avada'),
);
$args = array(
'label' =>__('gallery','Avada'),
'description' =>__('Gallery','Avada'),
'labels' =>$labels,
'supports' => array('title','editor','author','thumbnail','custom_fields'),
'hierarchical' =>false,
'public' =>true,
'show_ui' =>true,
'show_ui_menu' =>true,
'show_in_nav_menus' =>true,
'show_in_adminbar' =>true,
'menu_position' =>5,
'menu_icon' =>'dashicons-format-gallery',
'can_export' =>true,
'has_archive' =>false,
'exclude_from_search'=>false,
'publicaly_queryable'=>true,
'capability_type' =>'post',
'taxonomies' => array( 'gallery-cat' )
);
register_post_type('gallery-images',$args);
register_taxonomy('gallery-cat','gallery-images', array(
'label' => 'Gallery Category',
'hierarchical' => true
));
}
add_action( 'init', 'custom_gallery_images', 0 );
taxonomy.php:-
<?php get_header();
$queried_object = get_queried_object();
$catID = $queried_object->term_id;
$term=get_term_by('id',$catID,'gallery-cat');
$slug=$term->slug;
$parent_cat_ID=$term->term_id;
?>
<?php
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $parent_cat_ID,
'order' => 'ASC',
'taxonomy' => 'gallery-cat'
);
$subcats = get_categories($args);
$id1 = $subcats ->term_id;
if($subcats){
echo '<div class="wrap_main_cat">';
foreach ($subcats as $sc) {
$id = $sc->term_id; ?>
<div class="wrap_perticular_cat">
<div class="a_warp">
<a href="<?php echo get_category_link($id);?>" >
<?php echo get_the_category_thumbnail([$id]); ?>
</a>
</div>
<div class="parent-cat-name">
<a href="<?php echo get_category_link($id);?>" >
<?php $t = $sc->name; echo $t; ?>
</a>
</div>
</div>
<?php
}
echo '</div>';
}else{
$args1 = array(
'post_type' => 'gallery-images',
'posts_per_page' => -1 ,
'post_status' => 'publish',
'gallery-cat' =>$slug,
'order' => 'ASC'
);
$loop = new WP_Query( $args1 );
?>
<div class="wrap_main_cat">
<?php
while ( $loop->have_posts() ){
$loop->the_post();
$featured_img_url = get_the_post_thumbnail_url();
?>
<div class="wrap_perticular_cat">
<div class="a_warp">
<a href="<?php echo $featured_img_url; ?>" data-fancybox="gallery">
<img src="<?php echo $featured_img_url; ?>" />
</a>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
<?php get_footer(); ?>
一切正常,但我正面临面包屑的问题。每当我点击任何类别的面包屑 主页> category_name> subcat_name
但我想要
首页>页面名称>类别名称>子类别名称
请求快速帮助!
谢谢你