• Resolved alisonn

    (@alisonn)


    I’d like to display the categories associated with a job on the single job listing page. Is there some code that I can add to the template ‘content-single-job_listing-meta.php’ to do this?

    • This topic was modified 5 years, 5 months ago by alisonn.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Here you are:

    <?php $terms = get_the_terms( $post->ID, 'job_listing_category' );								
    if ( $terms && ! is_wp_error( $terms ) ) : 
    $jobcats = array();
    foreach ( $terms as $term ) {
    $term_link = get_term_link( $term );
    $jobcats[] = '<a href="'.$term_link.'">'.$term->name.'</a>'; }
    $print_cats = join( " / ", $jobcats ); ?>
    <span class="job-category"><?php echo $print_cats;?></span>
    <?php endif; ?>

    @kibus90 @alisonn
    Just a shorter way, which gets the tob done for us

    <li class="job-category <?php echo get_the_job_category() ? sanitize_title( get_the_job_category()->slug ) : ''; ?>"><?php the_job_category(); ?></li>

    Thread Starter alisonn

    (@alisonn)

    First, apologies for taking so long to reply

    @kibus90 that works!

    @braehler that didn’t work on my site

    Many thanks to you both

    @alisonn
    sorry, but I forgot to mention that my code this is based on the “category colors add on”

    Thread Starter alisonn

    (@alisonn)

    @braehler thanks for letting me know – will try that out

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display categories on single job listing’ is closed to new replies.