繁体   English   中英

如何设置类别链接以显示自定义页面模板?

[英]How can I set a category link to show a custom page template?

大家! 所以,我正在使用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会显示类别的链接(单击后返回“未找到”页面)。 我想知道是否可以更改此方法来调用我的自定义模板页面。 如果是这样,我该怎么做?

您可以创建一个类似于category-categoryname.php的PHP文件,并将其放入子主题function.php中,并在文件中放置以下代码(例如:-documentation)

<?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>&nbsp;<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(); ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM