Template To List All Child or Sub Categories of One Parent Category in Genesis

This template enables you to display a list of all child categories for the one parent category and updates dynamically after you add more child categories to any existing or new parent category.

Update : Here’s another solution List Child Categories of Parent Category With Image

A member of WP Sites asked me this question which is the reason i worked out this solution and wrote the tutorial:

I would like to understand how I can add create a page displaying a list of specific subcategories. I’m using the Magazine Pro theme by StudioPress.

Here’s the code for logged in members:

Related Code


Comments

13 responses to “Template To List All Child or Sub Categories of One Parent Category in Genesis”

  1. officethug Avatar
    officethug

    Brad, this is great – thank you!

    How do I move the Title under the image so it looks like a caption?
    And how do I add the Page title to the top of the page?

    1. Brad Dalton Avatar
      Brad Dalton

      Zac

      Which code snippet did you use and what exactly do you want to do because there maybe a better solution?

      1. officethug Avatar
        officethug

        Thanks Brad. I am trying to create a portfolio within Genesis with a grid layout. I want the PORTFOLIO page to display the thumbnail and title for each of the child categories in portfolio. If you click on a child category I want that page to display the children for that category or if there are no children, display the posts in that category. I think the solution here will work well but if you have any other ideas I would love your help.

        1. Brad Dalton Avatar
          Brad Dalton

          Did you use the first code snippet or other one?

        2. Brad Dalton Avatar
          Brad Dalton

          Try this code which adds the page title.
          [code]
          add_action( ‘genesis_loop’, ‘genesis_standard_loop’, 5 );
          [/code]

          Also, change the class to entry. Otherwise, there are other solutions.

          I think the image is added via the plugin?

          1. officethug Avatar
            officethug

            Brad, thanks again for your help. The code to display the page title worked and the plugin worked for the images. The grid layout is there too so the only thing left is moving the Category names below the images. I tried changing the class to Entry but that just made the font big so I switched it back to entry-title. Here is the page if you want to see what I mean: http://zakyoung.com/av/materials/

          2. Brad Dalton Avatar
            Brad Dalton

            Can’t you simply reposition the entry title. Here’s an example, simply change the hook position

            Or

            You could add the remove action and add action inside a custom function.

            Here’s a more specific solution http://wpsites.net/web-design/reposition-featured-image-on-any-genesis-archive-page/

            You can also try something like this:

            [code]
            remove_action( ‘genesis_entry_header’, ‘genesis_do_post_title’ );
            add_action( ‘genesis_entry_footer’, ‘genesis_do_post_title’, 5 );
            [/code]

  2. Cathie Avatar

    Is it possible to add the ability for it to automatically figure out the parent ID based on the url slug (or other item) so that it one code will work regardless of which archive taxonomy is being called?

    ie. if in the photography category it will pull up: newborn, family etc but if its the paint category it will pull up: matt, gloss, etc.

    This way it means that I don’t have to write this specifically for each category and it can instead just realise, yes I’m on an archive that has child taxonomies and list them with links.

    Thanks,
    Cathie.

    1. Brad Dalton Avatar
      Brad Dalton

      Help Cathie

      Sorry but don’t follow. Please clarify what you want.

      1. Cathie Avatar

        Sorry I wasn’t clear. Above you’ve manually set category ‘3’, is there a way to automatically get the parent category ID, depending on the page you’re on? So for example if I’m in the parent and also any child category of ‘photography’ it would output the list automatically of ‘family photography’ and ‘newborn photography’.

        This way we don’t have to manually set which categories have children, but that it can automatically figure out .. is this taxonomy archive one that has children .. if so, output relevant child taxonomies within that hierarchy.

        Thanks.
        Cathie.

        1. Brad Dalton Avatar
          Brad Dalton

          The code only generates 1 template for child categories of one parent category. The Codex doesn’t provide any examples of the values you can use for each parameter therefore its hard to say how or which parameter to modify and which value to use so the template displays all sub categories from all parent categories, if thats what you want it to do.

          Here’s the 2 parameters you can try modifying:

          child_of

          (integer) Display all categories that are descendants (i.e. children & grandchildren) of the category identified by its ID. There is no default for this parameter. If the parameter is used, the hide_empty parameter is set to false.

          parent

          (integer) Display only categories that are direct descendants (i.e. children only) of the category identified by its ID. This does NOT work like the ‘child_of’ parameter. There is no default for this parameter. [In 2.8.4]

  3. Hi Brad, thanks for this tutorial! It works fine. But would it be possible to display a thumbnail image for each subcategory? I tried using plugins to add images to taxonomies (Taxonomy Images: https://wordpress.org/plugins/taxonomy-images/; Genesis Taxonomy Images: https://wordpress.org/plugins/genesis-taxonomy-images/) but the thumbnail is not displayed.
    I guess I need to change the php code in the template but I don’t know how. I read here that it’s possible though: https://wordpress.org/support/topic/plugin-taxonomy-images-thumbails-with-subcategory-list.

    1. Brad Dalton Avatar
      Brad Dalton

      Updated the tutorial with the code for the images.

      You can use CSS to display them in a grid.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.