Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The function below is typically used when inside a loop of categories in order to return each category's description. I'm trying to use it to return the individual category's description when viewing a category landing page (mysite/category/somecategory).

How do I pass the equivalent object that represents the category?

On header.php

if(is_archive()) {
//get the category description
echo get_cat_desc(get_query_var( 'category' ))
}

In functions.php

function get_cat_desc($category){
  $the_description = strip_tags($category->description);
  if(strlen($the_description) > 200 ) 
return  SUBSTR( $the_description,0,STRPOS( $the_description,".",200)+1);
else return  $the_description;
}

Here is the function where I'm successfully passing in the category object to the function above...

function my_category_index(){
$categories=get_categories('exclude=1&exclude_tree=1');
foreach($categories as $category) {echo ce4_get_cat_desc($category);}
}
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted
get_cat_desc(get_category(get_query_var( 'category' )));

(get_category)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.