• Is it possible to use wp_list_categories in single post mode but only showing the categories related to the post shown?

    I’ve tried a few arguments but failed.

    Is there a similar plugin/function for this purpose?

    My main purpose is to show the categories under the post but in a format like the hierarchy in the widget.

    Thanks

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

    (@archillez)

    Here’s my code inserted in the template

    $categories = get_the_category ($post->ID);
    
    $includes = array();
    foreach ($categories as $c){$includes[]= $c->cat_ID;}
    asort($includes);
    
    $include="";
    foreach ($includes as $inc){
      if($include)$include .= ',';
      $include .= $inc;
    }
    
    $orderby      = 'slug';
    $show_count   = 1;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title_li = '';
    
    $args = array(
      'include'	 => $include,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'hierarchical' => $hierarchical,
      'title_li'        => $title_li,
    );
    wp_list_categories ($args);

    I can see the category list but the hierarchy is not seen.

    Nevermind, it is because my post didn’t have the parent category checked.

Viewing 1 replies (of 1 total)

The topic ‘Using wp_list_categories in single.php ?’ is closed to new replies.