• Resolved Amit K

    (@amitshrikulkarni)


    Hi,

    Hi Anders. Thank you for this beautiful and minimalist theme. This goes well with my requirement and I absolutely this theme. Can I get a solution to a very small problem?
    How can I show category name under the title for every post on archive page or home page?

    • This topic was modified 4 years, 10 months ago by Amit K.
    • This topic was modified 4 years, 10 months ago by Amit K.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Amit K

    (@amitshrikulkarni)

    I tried adding below code in content.php but it breaks the existing layout.

    <p> <?php the_category( ‘, ‘ ); ?> </p>

    • This reply was modified 4 years, 10 months ago by Amit K.
    Theme Author Anders Norén

    (@anlino)

    Hi @amitshrikulkarni,

    the_category() outputs the post categories wrapped in a elements — links — and since the content of content.php is already wrapped in a link, the post category links break the wrapper. You’ll need to create a custom loop with get_the_category(), and output the category names without links.

    Adding the following to content.php should do the trick:

    <?php if ( $categories = get_the_category() ) : ?>
    	<div class="preview-categories">
    		<?php
    		$categories_str = '';
    		foreach ( $categories as $category ) {
    			$categories_str .= $category->name . ', ';
    		}
    		echo rtrim( $categories_str, ', ' );
    		?>
    	</div><!-- .preview-categories -->
    <?php endif; ?>

    — Anders

    Thread Starter Amit K

    (@amitshrikulkarni)

    Thanks a lot, Anders. This worked ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category under Title in archive view’ is closed to new replies.