WordPress.org

Ready to get started?Download WordPress

Forums

How do I grab just the children of a parent category? (7 posts)

  1. Monkeyboy
    Member
    Posted 4 years ago #

    I'm creating a film review website, and have a Parent category called "Genre". Under this, are child categories such as "Horror", "Thriller" etc.

    On each film review page, I'm creating a small 'Film Details' box, with cast, director etc. For most of the info, I'm making use of Custom Fields. But I'd also like to put the genre child categories in there, seperated by a comma. I also don't want them outputting as links, just plain text.

    Is there any easy way to get just the child categories of another category? I've looked through the codex, but can't seem to find a way to do it.

  2. MichaelH
    Member
    Posted 4 years ago #

    Look at child_of= argument with get_categories.

  3. Monkeyboy
    Member
    Posted 4 years ago #

    Thanks very much. Still took a bit of figuring out, after looking at that part of the codex, but I got there in the end. :-)

  4. Monkeyboy
    Member
    Posted 4 years ago #

    Actually, I thought I'd cracked this, but turns out I haven't. Using get_categories, it seems I can only get all the child categories, when I actually want to get just the child categories relevant to the current post...

    But I can't seem to see a parameter that would let me do this. Can anyone help?

  5. MichaelH
    Member
    Posted 4 years ago #

    Well Template_Tags/get_the_category returns the categories for the current post.

  6. irina85
    Member
    Posted 4 years ago #

    I want almost exactly what Monkeyboy wants except that I want to have the current category's child displayed as a link.

    As far as I figured it out get_the_category does not provide child_of functionality, hence I can't get the child of a certain current category displayed.

    My example:

    Post A is filed under parent category Celebrities (id 1) and child category Brad Pitt (id 2). What I want to get displayed in the post is the child category link as the cat name (<a href="#categorylink">Brad Pitt</a>).

  7. guyperea
    Member
    Posted 4 years ago #

    Brad Pitt Brithday is 12/18/1964

Topic Closed

This topic has been closed to new replies.

About this Topic