- This topic has 2 replies, 3 voices, and was last updated 6 years, 5 months ago by .
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.
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.
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.
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.
© 2023 WPEngine, Inc.