Quick code question: get the category nicename
-
Hello,
I found the following at the wordpress codex and it’s really useful for my category archives page:
<?php $args=array( 'orderby' => 'name', 'order' => 'ASC' ); $categories=get_categories($args); foreach($categories as $category) { echo '<p>Category: <a>term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> '; echo '<p> Description:'. $category->description . '</p>'; echo '<p> Post Count: '. $category->count . '</p>'; } ?>
Is there a way I can get the category nice name (slug?), not the whole link? I want to create custom div classes depending on the category. I’m not an expert. I use the following for normal blog posts, but I can’t find a way to get this to work with the above code.
$category = get_the_category(); $posttitle .= $category[0]->category_nicename;
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Quick code question: get the category nicename’ is closed to new replies.