Support » Plugin: Responsive Posts Carousel » Show more than one category

  • Resolved Svensson36

    (@svensson36)


    Hi,
    I use the template “post display style 3” and I want to display all categories which belong to one post. Unfortunately only one category ist displayed, I think it is the category first in the alphabet.
    How can I display all categories belonging to one post?

    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rameez Iqbal

    (@rameez_iqbal)

    Hi, please go to file inc/templates/post-display-style-3.php
    and replace following code

    	<div class="rpc-post-category">
    		<?php $categories = get_the_category();
    			$separator = ' , ';
    			$output = '';
    			if ( ! empty( $categories[0] ) ) {
    			        $output .= '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>' . $separator;
    			    echo trim( $output, $separator );
    			}
    		?>
    	</div>

    with this one

    	<div class="rpc-post-category">
    		<?php $categories = get_the_category();
    			$separator = ' , ';
    			$output = '';
    			foreach ($categories as $cat) {
    				if ( ! empty( $cat ) ) {
    				        $output .= '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '">' . esc_html( $cat->name ) . '</a>' . $separator;
    				    echo trim( $output, $separator );
    				}
    			}
    		?>
    	</div>
    Svensson36

    (@svensson36)

    Hi,
    thanks a lot. but this displayed every category many times. I changed your code to this:

    <div class="rpc-post-category">
    <?php $categories = get_the_category();
    $separator = ' , ';
    $output = '';
    foreach ($categories as $cat) {
    if ( ! empty( $cat ) ) {
    $output .= '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '">' . esc_html( $cat->name ) . '</a>' . $separator;
    }
    }
    echo trim( $output, $separator );
    ?>
    </div>

    This means I put the “echo trim( $output, $separator );” after “foreach”. Now it works great!

    Thank you for the quick answer!

    • This reply was modified 1 year ago by Svensson36.
    Plugin Author Rameez Iqbal

    (@rameez_iqbal)

    That’s great.

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show more than one category’ is closed to new replies.