Support » Plugin: Simple News » Display category name

  • Resolved klfrnds

    (@klfrnds)


    Hi thanks for the plugin. Now i need to display category names for every news which i have shown in the above url. Thanks in advance.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author MortenPeterAndersen

    (@mortenpeterandersen)

    An easy way is to divide all the news like this:

    <h3>Cat name 1</h3>
    [news cat=1]
    
    <h3>Cat name 2</h3>
    [news cat=2]
    
    <h3>Cat name 3</h3>
    [news cat=3]

    … but you want the cat name inside the news … am I right?
    If that’s the case, then I have to change the coding in the plugin.

    πŸ™‚
    Morten

    Thread Starter klfrnds

    (@klfrnds)

    Thanks for your update. Yes you are right. I need to display the category name next to the date.

    Eg. If my news tagged with c1, c2 and c3 category means, the output will be
    12/12/2019 c1 c2 c3
    Kindly help me to bring display the category name.

    Plugin Author MortenPeterAndersen

    (@mortenpeterandersen)

    Hi klfrnds

    If you have the courage, try changing the line 28 in the functions.php (folder = files)

    from:
    echo '<div class="simple-news-date">' . get_the_date() . '</div>';
    to:
    echo '<div class="simple-news-date">' . get_the_date() . ' - ' . '<span class="simple-news-categories" >' . get_the_category_list( ', ' ) . '</span></div>';

    Please let me know if it helps

    πŸ™‚
    Morten

    Thread Starter klfrnds

    (@klfrnds)

    Hi thanks a lot. That is working fine. Once again thanks for your quick support.
    Only thing is the link given to the category need to be removed. Can you please guide me to remove that.

    Is there is a way to add sorting using the category?

    Plugin Author MortenPeterAndersen

    (@mortenpeterandersen)

    I think this should work.
    Change line 28 to this instead:

    	$categories = get_the_category();
    	$separator = ', ';
    	$output = '';
    	if ( ! empty( $categories ) ) {
    	  foreach( $categories as $category ) {
    	    $output .=  esc_html( $category->name ) . $separator;
    	  }
    	  echo '<div class="simple-news-date">' . get_the_date() . ' - ' . '<span class="simple-news-categories">' . trim( $output, $separator ) . '</span></div>';
    	}

    I think your idea with displaying the category name is something I will implement in the next update – thanks πŸ™‚

    Morten

    Thread Starter klfrnds

    (@klfrnds)

    Hi thanks. If the above code is working fine. But if i used it like means, i can not able to show it separately. Because it is coming by (, seperator). Thanks for your support. I will get back to you if needed anything.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display category name’ is closed to new replies.