WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Under Categories in Sidebar (3 posts)

  1. ernaparalla
    Member
    Posted 1 year ago #

    Hi all,
    This is proving more difficult that I had thought. Currently only the categories in my portfolio sidebar are shown but I would like to click on each category menu item and have all posts titles within it appear below, with only one category allowed 'open' at a time. Additionally, I would like this same sidebar to be displayed as you navigate from portfolio landing page to all posts within a specific category to a single portfolio post.

    Category A
    Category B
    Post 1
    Post 2
    Post 3
    Category C

    Existing code for sidebar in Portfolio Page Template (template-portfolio.php)

    <!--BEGIN .sidebar -->
                	<div class="sidebar">
                        <?php the_content(); ?>
                         <ul id="filter">
                          <?php wp_list_categories(array('title_li' => '', 'taxonomy' => 'skill-type', 'walker' => new Portfolio_Walker())); ?>		
    
                    <!--END .sidebar -->

    Existing code in functions.php:

    class Portfolio_Walker extends Walker_Category {
       function start_el(&$output, $category, $depth, $args) {
          extract($args);
          $cat_name = esc_attr( $category->name);
          $cat_name = apply_filters( 'list_cats', $cat_name, $category );
    	  $link = '<a href="#">term_id.'" ';
          if ( $use_desc_for_title == 0 || empty($category->description) )
             $link .= 'title="' . sprintf(__( 'View all items filed under %s' ), $cat_name) . '"';
          else
             $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
          $link .= '>';
          // $link .= $cat_name . '</a>';
          $link .= $cat_name;
          if(!empty($category->description)) {
             $link .= ' <span>'.$category->description.'</span>';
          }
          $link .= '';
          if ( (! empty($feed_image)) || (! empty($feed)) ) {
             $link .= ' ';
             if ( empty($feed_image) )
                $link .= '(';
             $link .= '<a>term_id, $feed_type) . '"';
             if ( empty($feed) )
                $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
             else {
                $title = ' title="' . $feed . '"';
                $alt = ' alt="' . $feed . '"';
                $name = $feed;
                $link .= $title;
             }
             $link .= '>';
             if ( empty($feed_image) )
                $link .= $name;
             else
                $link .= "<img src='$feed_image'$alt$title" . ' />';
             $link .= '</a>';
             if ( empty($feed_image) )
                $link .= ')';
          }
          if ( isset($show_count) && $show_count )
             $link .= ' (' . intval($category->count) . ')';
          if ( isset($show_date) && $show_date ) {
             $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
          }
          if ( isset($current_category) && $current_category )
             $_current_category = get_category( $current_category );
          if ( 'list' == $args['style'] ) {
              $output .= '<li class="segment-'.rand(2, 99).'"';
              $class = 'cat-item cat-item-'.$category->term_id;
              if ( isset($current_category) && $current_category && ($category->term_id ==
    $current_category) )
    $class .= ' current-cat';
    elseif ( isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent) )
    $class .= ' current-cat-parent';
    $output .= '';
    $output .= ">$link\n";
    } else {
    $output .= "\t$link\n";
    }
    }
    }`

    Thanks!

  2. DD_NYC
    Member
    Posted 1 year ago #

    I would like to do the same thing....
    Any wizards out there who can lend a hand?
    Thanks!

  3. lionsdendesigns
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic