• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How do you list parent categories first on a post?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How do you list parent categories first on a post?

This topic is: not resolved

Tagged: get_the_category_list, post_categories

  • This topic has 2 replies, 3 voices, and was last updated 9 years, 1 month ago by Brad Dalton.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • June 20, 2017 at 9:39 pm #208014
    lking31646
    Participant

    I have two categories showing on posts. One is the parent the other is the subcategory the post belongs to.

    They currently show alphabetically. I need to know how to list parent first then subcategory.

    I'm assuming this will be some sort of update to functions.php.

    Thanks.

    http://bestmens.com/best-white-sneakers-for-men/
    June 21, 2017 at 11:52 am #208038
    Victor Font
    Moderator

    You have to create your own function for displaying the categories in the order you want. To display the categories, Genesis calls the WordPress get_the_category_list() function to retrieve the categories assigned to a post. This function does accept parameters to display the parent category first, but the function returns the parent category twice and there's no way to change this. You have the parent listed first and then listed the second time wherever it falls into place alphabetically with the other categories.

    If you use one of the parameters to list the parent first, your example would come out style, shoes, style. So then, if you wanted to display the categories as style, shoe, you would start by copying the genesis_post_categories_shortcode function from the genesis/lib/shortcodes/post.php file. Don't change anything in this file. Copy this into your child theme's functions.php and rename the function to my_custom_post_categories_shortcode, perhaps.

    You can add the parameter 'multiple' to the get_the_category_list function. This will return the 3 tags. parent, tag, tag. Now here's the tricky part. The function returns all of the categories formatted as a single string. You would have search that string and parse out the second instance of the parent tag wherever it is located.

    Of course, you have the option of writing your own version of the get_the_category_list function and do the sorting and parsing there. Then call your version instead of get_the_category_list.

    This is not easy coding at all. Good luck with it.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    June 22, 2017 at 2:51 am #208063
    Brad Dalton
    Participant

    You might find it easier using wp_list_categories in replace of get_the_category_list because of the larger range of parameters and build your own custom post_categories shortcode.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble