mercuryfenix
Member
Posted 2 years ago #
I want my category template to load a landing page with an identical slug since the category description in WordPress doesn't have a rich text editor.
So if the URL to a category page looks like this:
http://mysite.com/?cat=163
Then the only data I have to work with is the category ID. What is the easiest way to get the category's slug?
mercuryfenix
Member
Posted 2 years ago #
My solution:
// pass single_cat_title("", false) to this function
function get_category_slug($single_cat_title)
{
global $wpdb;
return $wpdb->get_var("SELECT slug FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id AND taxonomy='category' AND name='$single_cat_title'");
}
Use it like this:
// get page with identical slug as category
$name = single_cat_title("", false);
$slug = get_category_slug($name);
query_posts("pagename=$slug");