Get post’s category name/ID

This gives you a way to display the current post’s Category ID and / or Category name.

Code Snippet:

<?php
foreach((get_the_category()) as $category) {
  $postcat= $category->cat_ID;
  $catname =$category->cat_name;
  echo $postcat;
  echo $catname;
}
?>

Posted in Posts