Output the same parent category title once
-
Hello codemaster,
I want to output category title only once even under the following situation.
Category X is a child category of A (A is a parent cat of X). In the post editing page of the WordPress when I select parent category “A” as well as the direct category of the post, “X”, before publishing. The following code outputs cat title A → A → X. Notice cat name “A” is output twice.
If I don’t select the parent category “A” but only “X” before publishing post, the cat title output will be correct which is A → X. “A” isn’t output twice.
My code is below..
is_singular('post') { $categories = get_the_category(); echo '<h2>'; foreach ($categories as $cat) { echo get_category_parents($cat, true, '<span class="category-separator"> → </span>'); } echo '</h2>'; }
It would be fantastic if you could give me advise.
Thank you.
Palmtree
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Output the same parent category title once’ is closed to new replies.