admin管理员组

文章数量:1277875

For my wp theme I want to use the categories as tags on my posts. Example:

The problem is that the category in red must always be the parent and in gold the child.

Except that returns the categories to me in alphabetical order and not in hierarchical order, so sometimes I end up with the child in red and the parent in gold ...

Knowing that I would only use 2 categories per posts so 1 = the parent and 2 = the child

Do you have a solution?

For my wp theme I want to use the categories as tags on my posts. Example:

The problem is that the category in red must always be the parent and in gold the child.

Except that returns the categories to me in alphabetical order and not in hierarchical order, so sometimes I end up with the child in red and the parent in gold ...

Knowing that I would only use 2 categories per posts so 1 = the parent and 2 = the child

Do you have a solution?

Share Improve this question asked Nov 8, 2021 at 17:55 MaximusMaximus 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 2

You could assign the post only to the child category, and call the function like so:

the_category( ' ', 'multiple' );

This will output (notice the whitepsace between the anchor tags):

<a href="https://example/category/parent/">parent</a> <a href="https://example/category/parent/child/" rel="category tag">child</a>

本文标签: phpEdit thecategory () for a hierarchical display