Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: list_cats

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 5 times in this file.

Line Code
336      $class = esc_attr( $class );
337      $id = $id ? esc_attr( $id ) : $name;
338
339      if ( ! $r['hide_if_empty'] || ! empty($categories) )
340           $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
341      else
342           $output = '';
343
344      if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
345           $show_option_none = apply_filters( 'list_cats', $show_option_none );
346           $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
347      }
348
349      if ( ! empty( $categories ) ) {
350
351           if ( $show_option_all ) {
352                $show_option_all = apply_filters( 'list_cats', $show_option_all );
353                $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
354                $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
355           }
356
357           if ( $show_option_none ) {
358                $show_option_none = apply_filters( 'list_cats', $show_option_none );
359                $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
360                $output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
361           }
362
363           if ( $hierarchical )
364                $depth = $r['depth'];  // Walk the full depth.
365           else
366                $depth = -1; // Flat.
367
 
Line Code
835       * @param object $category Category data object.
836       * @param int    $depth    Depth of category in reference to parents. Default 0.
837       * @param array  $args     An array of arguments. @see wp_list_categories()
838       * @param int    $id       ID of the current category.
839       */
840      function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
841           extract($args);
842
843           $cat_name = esc_attr( $category->name );
844           $cat_name = apply_filters( 'list_cats', $cat_name, $category );
845           $link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
846           if ( $use_desc_for_title == 0 || empty($category->description) )
847                $link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
848           else
849                $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
850           $link .= '>';
851           $link .= $cat_name . '</a>';
852
853           if ( !empty($feed_image) || !empty($feed) ) {
 
Line Code
952       *
953       * @param string $output   Passed by reference. Used to append additional content.
954       * @param object $category Category data object.
955       * @param int    $depth    Depth of category. Used for padding.
956       * @param array  $args     Uses 'selected' and 'show_count' keys, if they exist. @see wp_dropdown_categories()
957       */
958      function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
959           $pad = str_repeat('&nbsp;', $depth * 3);
960
961           $cat_name = apply_filters('list_cats', $category->name, $category);
962           $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
963           if ( $category->term_id == $args['selected'] )
964                $output .= ' selected="selected"';
965           $output .= '>';
966           $output .= $pad.$cat_name;
967           if ( $args['show_count'] )
968                $output .= '&nbsp;&nbsp;('. $category->count .')';
969           $output .= "</option>\n";
970      }