• I am trying to make a list in my sidebar of Categories with a sub list of the posts in that category… somewhat like this:

    <ul>
    <li>
        <a href="category_url">CATEGORY</a>
    
    <ul>
    <li><a href="post_url">POST</a></li>
    </ul>
    </li>
    </ul>

    Obviously I would like this to loop until it has played out all categories and posts within them.

    I am looking for tha code to make this happen in the same list format as I have custom styled menu tool in which i would like this code snippet to play out… so i need to di this WITHOUT A PLUGIN.

    Would really appreaciate any help!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter gadzira

    (@gadzira)

    No takers??

    Thread Starter gadzira

    (@gadzira)

    Still no one able to give any assistance?

    Thread Starter gadzira

    (@gadzira)

    Whats the use of this support forum if there is no contribution 🙁

    I would really appreciate any input with this.

    Hi,

    Don’t know whether you still need help in this area, but I have the same requirement and have had no luck in finding a built in WordPress function to do it. I have therefore knocked the code below together, feel free to use it.

    It builds an Unordered List of top level categories and then a nested UL of the appropriate posts. It adds links to both the category list page and the posts themselves.

    If you need any help with it or if it doesn’t quite do everything you need, let me know and I could add to it for you.

    To make it look good, you will have to do the appropriate CSS.

    <div id="sidebar">
        <ul>
            <?php
                $categories=get_categories();
                foreach($categories as $category) {
                    echo '<li><a href="'.get_category_link($category->cat_ID).'"><h2>'.$category->category_nicename."</h2></a></li><ul>";
                    $category_posts=get_posts('category='.$category->cat_ID);
                    foreach($category_posts as $post) {
                        echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
                    };
                    echo "</ul>";
                }; ?>
        </ul>
    </div>

    How would you do this for a specific category and all of its post?

    Many thanks AMP2307. Your code got me up and running. I found that if I used “name” instead of “category_nicename” the categories were capitalized, which is what I wanted.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Advanced category and post list’ is closed to new replies.