• S Curtis

    (@shaggy70)


    Hi,

    I am trying to display only the top level of categories, on a category page. to be clearer, when a category is selected in the menu, it shows only the child posts of that category, and not the grandchildren.

    Have been puzzling over this for a few days know. but must be missing something basic. This is the code for my category page. Any help much appreciated. Thanks.

    <?php get_header(); ?>

    <div id=”content”>
    <h1><?php printf( __( ‘%s’ ), ‘<span>’ . single_cat_title( ”, false ) . ‘</span>’ ); ?></h1>
    <?php echo category_description(); /* displays the category’s description from the WordPress admin */ ?>

    <div class=”cat-grid”>
    <?php
    if (have_posts()) : while (have_posts()) : the_post();

    // The following determines what the post format is and shows the correct file accordingly
    $format = get_post_format();
    get_template_part( ‘includes/post-formats/’.$format );

    if($format == ”)
    get_template_part( ‘includes/post-formats/standard’ );

    ?>

    <?php endwhile; else: ?>

    <div class=”no-results”>
    <?php echo ‘<p>‘ . __(‘There has been an error.’, ‘theme1774’) . ‘</p>’; ?>
    <p><?php _e(‘We apologize for any inconvenience, please’, ‘theme1774’); ?> /” title=”<?php bloginfo(‘description’); ?>”><?php _e(‘return to the home page’, ‘theme1774’); ?> <?php _e(‘or use the search form below.’, ‘theme1774’); ?></p>
    <?php get_search_form(); /* outputs the default WordPress search form */ ?>
    </div><!–no-results–>

    <?php endif; ?>
    </div>
    <?php get_template_part(‘includes/post-formats/post-nav’); ?>

    </div><!–#content–>

    <?php get_footer(); ?>

  • The topic ‘Display only top level categories.’ is closed to new replies.