• Resolved samanime

    (@samanime)


    I have a bunch of categories which have children categories within them.

    Right now, if I try to visit the page for a parent category all it displays is “No topics found”. What I’d like to have happen is that if it’s a parent category, it would list all of it’s children categories, and possibly even nested list with all of the topics in the category (just the title).

    Anyone have ideas about how to get started? I don’t need the details involved, just an idea of what functions I can use to get the information I want.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • get_query_var('cat'); // The current category ID being queried.

    https://codex.www.ads-software.com/Function_Reference/get_term – to get information on the category …

    If the parent is 0, it’s top level…

    https://codex.www.ads-software.com/Function_Reference/get_terms
    Use to get categories, use the “parent” parameter …

    Check the parent, then query for categories based on what the parent is, ie. if it’s 0 then you know it’s top level..

    Does that help?.. you said you just needed some ideas of where to start.

    NOTE: 2 functions above do differ, notice the names, get_term and get_terms

    Thread Starter samanime

    (@samanime)

    Thanks for the help. After I posted this I went and experimented and got it working on my own.

    I used get_categories(“child_of=” . $parentID) to get the children categories, then used the following code block to get it to print out how I wanted:

    foreach($children as $child) {
    		echo "
    <li><h2>" . htmlentities($child->name) . "</h2>";
    		echo "
    <ul>";
    		$posts = get_posts('cat=' . $child->cat_ID . '&orderby=title&order=ASC&numberposts=-1');
    		foreach($posts as $post)
    			echo "
    <li><a>post_ID) . "\">" . htmlentities($post->post_title) . "</a></li>
    ";
    		echo "</ul>
    ";
    		echo "</li>
    ";
    	}

    Hopefully that’ll help anyone trying to do this in the future.

    EDIT: Oh, I also ended up getting the category I was using with:
    $cat = get_category_by_path($_SERVER[‘SERVER_NAME’] . $_SERVER[‘REQUEST_URI’],false);

    Though, actually, I think I’m gonna switch it to your method. I like it better. =p

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List Children Categories on Parent Category Page’ is closed to new replies.