• Hey Hey,

    For some reason, I can wrap my head around this one today…

    I’m using the “Triple loop” from Perishable Press (links to the tutorial). Any way, it works great. the issue I’m having is that inside each one of those loops I need to display all the sub-categories of a post as class inside the “li” that it’s housed in.

    Any Suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • http://codex.wordpress.org/Function_Reference/get_the_category
    http://codex.wordpress.org/Function_Reference/get_categories

    <?php $cats = get_the_category($post->ID);
    foreach( $cats as $cat ) {
      $subcats = get_categories('child_of='.$cat->term_id);
      $kits = array();
      if($subcats) {
        foreach( $subcats as $subcat )
          { $subcategories[] = $subcat->slug; }
      }
    }
    $subcategories = array_unique($subcategories);
    if($subcategories) {
      $subcategories = implode(' ',$subcategories);
      echo 'class="' . $subcategories . '"';
    }
    ?>
    Thread Starter sdjentertainment

    (@sdjentertainment)

    Thanks for that, but it’s not quite working the way I want…

    So inside of the main loop (index.php) I have it targeting the specific category

    <?php query_posts('cat=14&showposts=3'); ?>
    <?php $posts = get_posts('category=14&numberposts=3&offset=0');
        foreach ($posts as $post) : start_wp(); ?>

    Then I have a ul with the li’s inside of that. I want to give each li in the loop a class of all the sub-categories that is assigned to it. For example

    <ul>
    <li class="Video Project"></li>
    <li class="Project About"></li>
    </ul>

    When I was using your code that you provided earlier I was getting some sub-categories names as Blog-Video. (Blog is the main Category)

    So in the above example I want to only have the sub-categories of category 14 (bold above) to show up.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Listing SubCategories as classes’ is closed to new replies.