如何在类别页面上显示子类别页面

时间:2016-12-21 作者:user2446202

在类别页面(www.mdrnfashion.com/nba-players/)上,我想显示在子类别页面(www.mdrnfashion.com/nba-players/lebron-james/)上,以及not 子类别的帖子。

这张图很好地概述了我试图实现的层次结构。enter image description here

这是我的分类。php

<?php
    get_header();
    $cb_cats = get_the_category();
    $cb_cat_id = get_query_var(\'cat\');
    $cb_blog_style = cb_get_blog_style();
    $cb_cat_title_bg = $cb_tax_id = $cb_taxonomy = $cb_tax_qry = NULL; 
    $cb_archive_title_bg_src = cb_archive_title_bg();

    if ( function_exists(\'get_tax_meta\') ) {

        $cb_category_color_style = get_tax_meta($cb_cat_id, \'cb_cat_style_color\');
        $cb_featured_option = get_tax_meta($cb_cat_id, \'cb_cat_featured_op\');
        $cb_category_ad = get_tax_meta_strip($cb_cat_id, \'cb_cat_ad\');
        $cb_category_color = get_tax_meta($cb_cat_id, \'cb_color_field_id\');
        if ( ($cb_category_color == \'#\' ) || ( $cb_category_color == NULL ) ) {

            $cb_parent_cat_id = $cb_cats[0]->parent;
            if ($cb_parent_cat_id != \'0\') {
                $cb_category_color = get_tax_meta($cb_parent_cat_id, \'cb_color_field_id\');
            }
        }

    } else {
        $cb_category_color = $cb_category_ad = NULL;
        $cb_featured_option = \'Off\';
    }

    if ( ($cb_category_color == NULL) || ($cb_category_color == \'#\')) {
         $cb_category_color = ot_get_option(\'cb_base_color\', \'#eb9812\');
    }

    if ( isset( $cb_archive_title_bg_src[1] )  ) {
        $cb_cat_title_bg =  \'data-cb-bg="\' . $cb_archive_title_bg_src[1] . \'"\';
    }
?>

<div id="cb-content" class="wrap clearfix">

<div id="cb-cat-header" class="cb-cat-header cb-section-header" style="border-bottom-color:<?php echo $cb_category_color; ?>;" <?php echo $cb_cat_title_bg; ?>>
    <h1 id="cb-cat-title"><?php echo get_category(get_query_var(\'cat\'))->name; ?></h1>
    <?php echo category_description( $cb_cat_id ); ?>
</div>

<?php 
if ( ( $cb_featured_option != \'Off\' ) && ( $cb_featured_option != NULL ) && ( $cb_featured_option != \'slider\' )  && ( $cb_featured_option != \'s-1\' ) ) {

    $cb_flipped = NULL;
    $j = 0;
    $cb_section = \'a\';
    include( locate_template( \'library/modules/cb-\'.$cb_featured_option.\'.php\' ) );

}

echo cb_breadcrumbs();

if ( ( $cb_featured_option != \'Off\' ) && ( $cb_featured_option != NULL ) && ( $cb_featured_option == \'s-1\' ) ) {

    $cb_flipped = NULL;
    $j = 0;
    $cb_section = \'a\';
    include( locate_template( \'library/modules/cb-\' . $cb_featured_option . \'.php\' ) );

}  
?>

<div class="clearfix">
    <div id="main" class="cb-main clearfix cb-module-block cb-blog-style-roll">

        <?php

            if ( $cb_category_ad != NULL ) {
                echo \'<div class="cb-category-top">\' . do_shortcode( $cb_category_ad ) . \'</div>\';
            }

            if ( $cb_featured_option == \'slider\' ) {
                $cb_section = $cb_title = $cb_module_style = $j = NULL;
                include( locate_template( \'library/modules/cb-s-2.php\' ) );
            }

            include( locate_template( \'cat-\' . $cb_blog_style . \'.php\') );

        ?>

    </div> <!-- /main -->

    <?php if ( $cb_blog_style != \'style-c\' ) { get_sidebar(); } ?>
    </div>

</div> <!-- end /#cb-content -->

<?php get_footer(); ?>
下面是一个类别样式的示例

    <?php /* Category/Blog Style A */

$cb_qry = cb_get_qry();

if ( $cb_qry->have_posts() ) : while ( $cb_qry->have_posts() ) : $cb_qry->the_post();
global $post;
$cb_post_id = $post->ID;
$cb_category_color = cb_get_cat_color( $cb_post_id );
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(\'cb-blog-style-a cb-blog-style cb-color-hover cb-separated clearfix\' ); ?> role="article">

<div class="cb-mask" style="background-color:<?php echo $cb_category_color; ?>;">

<?php
    cb_thumbnail(\'360\', \'240\');
    echo cb_review_ext_box( $cb_post_id, $cb_category_color );
?>

</div>

<div class="cb-meta">

  <h2 class="cb-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  <?php echo cb_byline(); ?>
  <div class="cb-excerpt"><?php echo cb_clean_excerpt( 210, false ); ?></div>

</div>

</article>

<?php

endwhile;
cb_page_navi( $cb_qry );
endif;
 wp_reset_postdata();
?>

1 个回复
SO网友:user2446202
<?php
    get_header();
    $cb_cats = get_the_category();
    $cb_cat_id = get_query_var(\'cat\');
    $cb_blog_style = cb_get_blog_style();

    $cb_cat_title_bg = $cb_tax_id = $cb_taxonomy = $cb_tax_qry = NULL; 
    $cb_archive_title_bg_src = cb_archive_title_bg();

    if ( function_exists(\'get_tax_meta\') ) {

        $cb_category_color_style = get_tax_meta($cb_cat_id, \'cb_cat_style_color\');
        $cb_featured_option = get_tax_meta($cb_cat_id, \'cb_cat_featured_op\');
        $cb_category_ad = get_tax_meta_strip($cb_cat_id, \'cb_cat_ad\');
        $cb_category_color = get_tax_meta($cb_cat_id, \'cb_color_field_id\');
        if ( ($cb_category_color == \'#\' ) || ( $cb_category_color == NULL ) ) {

            $cb_parent_cat_id = $cb_cats[0]->parent;
            if ($cb_parent_cat_id != \'0\') {
                $cb_category_color = get_tax_meta($cb_parent_cat_id, \'cb_color_field_id\');
            }
        }

    } else {
        $cb_category_color = $cb_category_ad = NULL;
        $cb_featured_option = \'Off\';
    }

    if ( ($cb_category_color == NULL) || ($cb_category_color == \'#\')) {
         $cb_category_color = ot_get_option(\'cb_base_color\', \'#eb9812\');
    }

    if ( isset( $cb_archive_title_bg_src[1] )  ) {
        $cb_cat_title_bg =  \'data-cb-bg="\' . $cb_archive_title_bg_src[1] . \'"\';
    }
?>

<div id="cb-content" class="wrap clearfix">

<div id="cb-cat-header" class="cb-cat-header cb-section-header"    style="border-bottom-color:<?php echo $cb_category_color; ?>;" <?php echo $cb_cat_title_bg; ?>>
        <h1 id="cb-cat-title"><?php echo get_category(get_query_var(\'cat\'))-             >name; ?></h1>
    <?php echo category_description( $cb_cat_id ); ?>
</div>
<div class="clearfix">
    <div id="main" class="cb-main clearfix cb-module-block cb-blog-style-roll">

        <?php

            $term = get_queried_object();
            $children = get_terms( $term->taxonomy, array(
                \'parent\'    => $term->term_id,
                \'hide_empty\' => true
                ) );

            $cb_count = 1;
            $cb_counter = 1;

            if($children) {

                foreach($children as $child){

                    if ( ( $cb_blog_style == \'style-b\' || $cb_blog_style == \'style-e\' ) && $cb_count == 3 ) { $cb_count = 1; }
                    if ( $cb_blog_style == \'style-c\' && $cb_count == 4 ) { $cb_count = 1; }
                    if ( $cb_blog_style == \'style-g\' && $cb_counter == 4 ) { $cb_counter = 1; }

                    if($cb_blog_style == \'style-a\'){ $image_size = \'cb-360-240\'; $post_class = \'cb-blog-style-a cb-blog-style cb-color-hover cb-separated clearfix\'; }
                    if($cb_blog_style == \'style-b\'){ $image_size = \'cb-360-240\'; $post_class = "cb-blog-style-b cb-blog-style cb-color-hover cb-article-row-2 cb-article-row cb-separated clearfix cb-no-$cb_count";}
                    if($cb_blog_style == \'style-c\'){ $image_size = \'cb-360-240\'; $post_class = "cb-blog-style-c cb-blog-style cb-color-hover cb-article-row-3 cb-article-row cb-separated clearfix cb-no-$cb_count";}
                    if($cb_blog_style == \'style-d\'){ $image_size = \'cb-750-400\'; $post_class = "cb-blog-style-d cb-blog-style cb-color-hover cb-separated clearfix";}
                    if($cb_blog_style == \'style-e\'){ $image_size = \'cb-300-250\'; $post_class = "cb-blog-style-e cb-small cb-blog-style cb-color-hover cb-article-row-2 cb-article-row cb-separated clearfix cb-no-$cb_count";}
                    if($cb_counter % 3  == 0 && $cb_blog_style == \'style-f\'){ $image_size = \'cb-750-400\'; $post_class = "cb-blog-style-d cb-blog-style cb-color-hover cb-separated clearfix";}
                    if($cb_counter % 3  != 0 && $cb_blog_style == \'style-f\'){ $image_size = \'cb-360-240\'; $post_class = \'cb-blog-style-a cb-blog-style cb-color-hover cb-separated clearfix\';}
                    if($cb_counter % 3  == 0 && $cb_blog_style == \'style-g\'){ $image_size = \'cb-750-400\'; $post_class = "cb-blog-style-d cb-blog-style cb-color-hover cb-separated clearfix";}
                    if($cb_counter % 3  != 0 && $cb_blog_style == \'style-g\'){ $image_size = \'cb-360-240\'; $post_class = "cb-blog-style-b cb-blog-style cb-color-hover cb-article-row-2 cb-article-row cb-separated clearfix cb-no-$cb_counter";}


                    ?>


                    <article <?php post_class( $post_class ); ?> >
                        <div class="cb-mask" style="background-color:<?php echo $cb_category_color; ?>;">
                            <a href="<?php echo get_term_link($child->term_id); ?>">
                                <?php z_taxonomy_image($child->term_id, $image_size ); ?>
                            </a>
                        </div>
                        <div class="cb-meta">
                            <h2 class="cb-post-title">
                                <a href="<?php echo get_term_link($child->term_id); ?>">
                                    <?php echo $child->name; ?>
                                </a>
                            </h2>
                            <?php if ($cb_blog_style != \'style-e\') { ?> <div class="cb-excerpt"><?php echo $child->description; ?></div> <?php } ?>
                        </div>
                    </article>



                    <?php

                    $cb_count++;
                    $cb_counter++;
                    }

            }
            else {

                if ( $cb_category_ad != NULL ) {
                    echo \'<div class="cb-category-top">\' . do_shortcode( $cb_category_ad ) . \'</div>\';
                }

                if ( $cb_featured_option == \'slider\' ) {
                    $cb_section = $cb_title = $cb_module_style = $j = NULL;
                    include( locate_template( \'library/modules/cb-s-2.php\' ) );
                }

                include( locate_template( \'cat-\' . $cb_blog_style . \'.php\') );

            }

        ?>

    </div> <!-- /main -->

    <?php if ( $cb_blog_style != \'style-c\' ) { get_sidebar(); } ?>
</div>