• Resolved mercuryfenix

    (@mercuryfenix)


    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:
    https://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?

Viewing 1 replies (of 1 total)
  • Thread Starter mercuryfenix

    (@mercuryfenix)

    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");

Viewing 1 replies (of 1 total)
  • The topic ‘get category name in category template’ is closed to new replies.