Created
April 2, 2015 09:19
-
-
Save hslaszlo/97da0f17ccb322694209 to your computer and use it in GitHub Desktop.
Get a category name/slug/id for a post or archive page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( is_single() ) { | |
$cats = get_the_category(); | |
$cat = $cats[0]; // let's just assume the post has one category | |
} | |
else { // category archives | |
$cat = get_category( get_query_var( 'cat' ) ); | |
} | |
$cat_id = $cat->cat_ID; | |
$cat_name = $cat->name; | |
$cat_slug = $cat->slug; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment