0

I want to display some texts in specific category in single post based on category in wordpress.. how can i do that

for example posts in news category display some text.(not all category)

Thank you

2
  • The same text for all posts? Where do you want the text to appear? Oct 29 '17 at 8:01
  • yes in particular category only same text
    – Daniel
    Oct 29 '17 at 8:05
0

Place this code in single.php where you need to show it:

<?php 
$catarray = get_the_category( $post->ID );
foreach ($catarray as $cat) {
    $catid = $cat->term_id;

    if ($catid == 5) {
      echo 'TEXT HERE';
    }
    if ($catid == 7) {
      echo 'ANOTHER TEXT';
    }

}
?>
5
  • Thank you for reply.. but i added it displays nothing i have added this code in single.php <?php $catarray = get_the_category( $post->ID ); $catid = $catarray[0]->term_id; //show text if category id is 5 if ($catid == 171) { echo 'kannada mp3 kannada songs'; } //another if ($catid == 48) { echo 'Kannada news'; } ?>
    – Daniel
    Oct 29 '17 at 8:41
  • where you put it? can upload scr?
    – techno
    Oct 29 '17 at 8:47
  • 1
    Do you have just a single category per post? Otherwise, you'll have to check all of them in the array $catarray.
    – janh
    Oct 29 '17 at 8:52
  • no i have multiple category for single post..added in single.php screenshot imgur.com/a/bKez2 results post newkannada.com/dheera-kannada-songs-download.html
    – Daniel
    Oct 29 '17 at 9:16
  • try updated answer.
    – techno
    Oct 29 '17 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.