Display selected categories onto post page

Question

I need to know how to display only the selected categories per post page..

Example. I am working on a website for movies. I have a category called Genre, then I have sub categories attached to that like comedy, horror etc…

Then I have a category called Availability and sub categories with like, USA, Mexico, England.. etc..

So I’ll need to have it set like this per post page.

Genres
Action/Adventure, Drama, New Releases

Availability
Untied States, England, France

I have this code, but I can’t figure out how to separate between genre and Availability

<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if ( ! empty( $categories ) ) {
    foreach( $categories as $category ) {
        $output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator;
    }
    echo trim( $output, $separator );
} ?>
0
, Timothy Rooker 6 years 2017-05-28T05:50:37-05:00 0 Answers 65 views 0

Leave an answer

Browse
Browse