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