大家好! 所以,我使用的是BreadCrumbs,代码如下:
//====== BreadCrumbs
function my_breadcrumbs() {
if(!is_front_page()) {
echo '<nav class="breadcrumb">';
echo 'Você está aqui: <a href="'.home_url('/').'">'."Início".'</a><span class="divider"><i class="fa fa-angle-double-right" aria-hidden="true"></i></span>';
if (is_category() || is_single()) {
the_category(' <span class="divider"><i class="fa fa-angle-double-right" aria-hidden="true"></i></span> ');
if (is_single()) {
echo ' <span class="divider"><i class="fa fa-angle-double-right" aria-hidden="true"></i></span> ';
the_title();
}
} elseif (is_page()) {
echo the_title();
}
echo '</nav>';
}
}
但是我有一个自定义模板页面来显示每个类别,当我在特定类别的帖子中时,BreadCrumbs会显示类别中的链接(单击时返回Not found页面)。我想知道是否有办法改变它来调用我的自定义模板页面。如果是这样,我怎么能这样做?
答案 0 :(得分:0)
你可以创建一个像category-categoryname.php这样的PHP文件并放入子主题function.php并将下面的代码放在文件中(例如: - 文档)
<?php get_header();?>
<div class="section">
<div class="section_wrapper clearfix">
<?php
echo '<div class="posts_wrapper clearfix">';
$current_category = get_the_category();
$current_category_id = $current_category[0]->cat_ID;
foreach( get_categories(array('hide_empty' => 0, 'child_of' => 78 ,'orderby' => 'count' , 'order' => 'DESC')) as $cat ) :
echo '<ul class="qa col-md-12"><li class="qa_category"><h2><strong><a style="color:#000;" href="' . get_category_link( $cat ) . '">' . $cat->name . '</a></h2></strong></li>';
process_cat_tree( $cat->term_id );
endforeach;
wp_reset_query(); //to reset all trouble done to the original query
function process_cat_tree( $cat ) {
$args = array(
'category__in' => array( $cat ),
'numberposts' => 6,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => 77,
),
));
$cat_posts = get_posts( $args );
if( $cat_posts ) :
echo '<div class="col-md-6">';
echo '<h6> Documentation </h6>';
foreach( $cat_posts as $post ) :
echo '<li class="qa">';
echo '<a style="color: #158ec2;" href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>';
echo '</li>';
endforeach;
if(count($cat_posts)>5)
echo '<a class="see-all-articles" href="' . get_category_link( $cat ) . '"> See all Articles </a> <br/>';
echo '</div>';
endif;
$next = get_categories('hide_empty=0&parent=' . $cat);
if( $next ) :
foreach( $next as $cat ) :
echo '<ul class="qa"><li class="qa_category"><strong>' . $cat->name . '</strong></li>';
process_cat_tree( $cat->term_id );
endforeach;
endif;
echo '</ul>';
}
echo '</div>';
?>
</div>
</div>
<?php get_footer(); ?>