0

I have assigned two different main categories to blog and portfolio.

the blog will show only categories related to main blog category and portfolio will also do the same.

with this code for portfolio

$cat_ids = get_all_category_ids();
foreach($cat_ids as $cat_id) {
$cat_name = get_cat_name($cat_id);
    $cat_slug = strtolower($cat_name);
    $cat_slug = str_replace(' ', '-', $cat_slug);
    if(get_category($cat_id) ) {

        echo '<li class="'.$cat_slug.'"><a href="#" rel="'.$cat_slug.'">'.$cat_name.'</a></li>';
    }
} // foreach 

i am getting all categories also blog.

i just want to show the categories related to 'portfolio' category on portfolio page.

  • you are creating blog and portfolio as parent category or the taxonomy – ksr89 Jun 25 '13 at 12:00
1

You can use get_categories() to get all the sub-category of parent category.

$args = array('hide_empty'=> 0,
              'child_of'=>'id_of_blog_category/id_of_portfolio_category');

$categories = get_categories($args);
foreach ($categories as $key => $value) {
    echo '<li class="'.$value->slug.'"><a href="#" rel="'.$value->slug.'">'.$value->name.'</a></li>';
}
  • Sorry my question was not well explained but your ans is correct as i was looking for thank you very much. – Abdul Shakoor Kakar Jun 26 '13 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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