• mhirschberg

    (@mhirschberg)


    How can I display a posts category? I’ve been trying to add to top-10.php code but nothing seems to work. I tried:

    $output .='<a href="' . $category->cat_ID . '" rel="category tag">' .$category->cat_name. '</a>'

    And

    $categories = get_the_category();
    $separator = ' ';
    $output = '';
    if($categories){
    	foreach($categories as $category) {
    		$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
    	}
    echo trim($output, $separator);
    }

    Neither works. Can you please help me out? Thanks!

    https://wordpress.org/plugins/top-10/

Viewing 1 replies (of 1 total)
  • Plugin Author Ajay

    (@ajay)

    Hi,

    Where are you putting this code?

    A cleaner (untested) option would be to add this to your functions.php

    function filter_tptn_after_list_item( $after_list_item, $result ) {
    
    $after_list_item .= get_the_category_list( ', ', '', $result->ID );
    
    return $after_list_item;
    
    }
    add_filter( 'tptn_after_list_item', 'filter_tptn_after_list_item', 10, 2);
Viewing 1 replies (of 1 total)

The topic ‘Display Category Name’ is closed to new replies.