• I have a wordpress blog, which i try to use as WebCMS, and i have certain parent categories with no content, but i would like to show the content of the next following children cetagroy instead.

    Here is my current code:

    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    		    <?php
              // check if the post belongs directly to the current category;
              // continue if not
              $current_categories = get_the_category();
              $found_category = false;
              foreach ($current_categories as $current_category) {
                if ($current_category->term_id == $cat) {
                  $found_category = true;
                  // counting level
                  $level = 0;
                  while ($current_category->parent != 0) {
                    $current_category = get_category($current_category->parent);
                    $level = $level + 1;
                  }
                  break;
                }
              }
              if (!$found_category) {
                continue;
              }
            ?>

    Additionally i have two releated issues to that children content one.

    1.) i use MyCategoryOrder Plugin, to sort the categories and i wuld like for the display of the content, to keep the same order/structure:

    <?php wp_list_categories('orderby=order&show_count=0&title_li=&depth=3'); ?>

    2.) by clicking on the parent category, my navigation menu starts displaying the children. Can i somehow mark the first children (which content should be displayed) with a “current_cat” css-class? So that the users know where he/she is?

    Thank You for your support in advance,
    bb

  • The topic ‘If no post in parent category jump to first children’ is closed to new replies.