Advertisement
Guest User

Extending Walcker_Category class in Wordpress.

a guest
Apr 23rd, 2012
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. class My_Walker_Category extends Walker_Category{
  2.     function start_el(&$output, $category, $depth, $args) {
  3.         extract($args);
  4.  
  5.         $cat_name = esc_attr( $category->name );
  6.         $cat_name = apply_filters( 'list_cats', $cat_name, $category );
  7.         if ( $category->parent > 0 ) {
  8.             $link = '<a href="' . esc_attr( get_term_link( $category ) ) . '" ';
  9.             if ( $use_desc_for_title == 0 || empty($category->description) )
  10.                 $link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
  11.             else
  12.                 $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
  13.             $link .= '>';
  14.         }
  15.             $link .= $cat_name;
  16.  
  17.         if ( $category->parent > 0 ) {
  18.             $link .= '</a>';
  19.         }
  20.  
  21.         if ( !empty($feed_image) || !empty($feed) ) {
  22.             $link .= ' ';
  23.  
  24.             if ( empty($feed_image) )
  25.                 $link .= '(';
  26.  
  27.             $link .= '<a href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"';
  28.  
  29.             if ( empty($feed) ) {
  30.                 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
  31.             } else {
  32.                 $title = ' title="' . $feed . '"';
  33.                 $alt = ' alt="' . $feed . '"';
  34.                 $name = $feed;
  35.                 $link .= $title;
  36.             }
  37.  
  38.             $link .= '>';
  39.  
  40.             if ( empty($feed_image) )
  41.                 $link .= $name;
  42.             else
  43.                 $link .= "<img src='$feed_image'$alt$title" . ' />';
  44.  
  45.             $link .= '</a>';
  46.  
  47.             if ( empty($feed_image) )
  48.                 $link .= ')';
  49.         }
  50.  
  51.         if ( !empty($show_count) )
  52.             $link .= ' (' . intval($category->count) . ')';
  53.  
  54.         if ( !empty($show_date) )
  55.             $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
  56.  
  57.         if ( 'list' == $args['style'] ) {
  58.             $output .= "\t<li";
  59.             $class = 'cat-item cat-item-' . $category->term_id;
  60.             if ( !empty($current_category) ) {
  61.                 $_current_category = get_term( $current_category, $category->taxonomy );
  62.                 if ( $category->term_id == $current_category )
  63.                     $class .=  ' current-cat';
  64.                 elseif ( $category->term_id == $_current_category->parent )
  65.                     $class .=  ' current-cat-parent';
  66.             }
  67.             $output .=  ' class="' . $class . '"';
  68.             $output .= ">$link\n";
  69.         } else {
  70.             $output .= "\t$link<br />\n";
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement