Get Your WordPress Post Category by ID

Do you need to get your WordPress Post Category by ID? This is a very handy piece of code to use within any of your theme templates.


$cat_name = $id = get_the_ID();
$categories = get_the_category($id);
$thepostcategorycheck = $categories['0']->slug;
if ($thepostcategorycheck == "news"){
echo 'View All News Articles >>';}
elseif ($thepostcategorycheck =="puppies"){
echo 'View All Articles on puppies >>';}