• Hi!

    I have a tricky question. I use a category-based navigation with subcategories and posts. I have the category navigation on top and a local navigation (on the left) shown below. what i need is that the working code for the category-page also works on the single.php or i use a different one with the same result:

    THATS WHAT I WANT ( https://www.goodandbad.net/sport-akustik/category/know-how/ ):
    title category parent category
    – posts in category
    subcategory 1(if existion)
    – posts in subcategory
    subcategory 2(if existion)
    – posts in subcategory

    HERE IS THE CODE:

    <backticks>

    <h2><?php echo $catname; ?></h2>

    <?php $categories = get_categories(“child_of=5”); foreach ($categories as $cat) { ?>

    <?php query_posts(“cat=$cat->cat_ID&showposts=-1&order=ASC&orderby=name”); ?>
    <h3><?php single_cat_title(); ?></h3>
    <?php while (have_posts()) : the_post(); ?>

    <div class=”what”>
    <h3>” rel=”bookmark” title=”Permanent Link to
    <?php the_title_attribute(); ?>”><?php the_title(); ?>
    </h3>
    </div>
    <?php endwhile; ?>
    <?php } ?>

    </backticks>

Viewing 16 replies (of 16 total)
  • Thread Starter deftru

    (@deftru)

    a little problem..
    the result is perfect.. just one tiny little thing.

    at the end it writes one subcategory with <h2>
    but i just want to display the parent category with <h2> on top (Ltd.)

    have a look:
    https://www.goodandbad.net/sport-akustik/limited/perfekte-akustik-im-fur-forschung-und-lehre/

    <?php
    $post_categories = wp_get_post_categories( $post->ID );
    foreach($post_categories as $c){
      $cat = get_category( $c );
      echo "<h1>". $cat->name . "</h1>";
      $childCats = get_categories( array('child_of' => $c) );
      if(is_array($childCats)):
        foreach($childCats as $child){ ?>
            <h2><?php echo $child->name; ?></h2>
    <?php
            query_posts('cat='.$child->term_id);
            while(have_posts()): the_post(); $do_not_duplicate = $post->ID;
             //post code stuff here;
            endwhile;
            wp_reset_query();
        }
      endif;
    }
    ?>

    Presse should not be displayed.
    would be glad if this could be fixed.

Viewing 16 replies (of 16 total)
  • The topic ‘Category Navigation on single.php’ is closed to new replies.