Wordpress - Check if posts belongs to a category


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3.  
  4. if ( in_category('News') ) {
  5. // belongs to cat
  6. }
  7.  
  8. // or array
  9. if ( in_category(array('News', 'Tools')) ) {
  10. // belongs to one or more of the categories
  11. }

URL: http://codex.wordpress.org/Function_Reference/in_category

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.