creating parent category and subcategory list in sidebar (2 posts)

  1. michaeloc
    Posted 4 years ago #

    Hi I am using code below in my sidebar.php to list posts from a category when on that category. It also lists posts from child category if there is one.

    What I would like to do is add a current menu item class to the list items

    I would also like to be able to indent the list items for child category posts


    parent category post 1
    parent category post 2
    > indent child category post 1
    > indent child category post 2
    parent category post 3

    <?php global $post;
    $categories = get_the_category();
    foreach ($categories as $category) :
    <h3 class="categories-menuheading">Menu</h3>
    <?php endforeach; ?>
    <ul id="kbo-category-menus">
    $posts = get_posts('numberposts=20&category='. $category->term_id);
    foreach($posts as $post) :
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
  2. michaeloc
    Posted 4 years ago #

    figured out the first part how to add current menu item class :) hope this helps others

    $postid = get_the_id();
    <li <?php if( $post->ID == $postid ) { echo class="current"'; } ?>></li>

Topic Closed

This topic has been closed to new replies.

About this Topic