Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: the_category

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 3 times in this file.

Line Code
166  * @param string $separator Optional, default is empty string. Separator for between the categories.
167  * @param string $parents Optional. How to display the parents.
168  * @param int $post_id Optional. Post ID to retrieve categories.
169  * @return string
170  */
171 function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
172      global $wp_rewrite;
173      if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
174           /** This filter is documented in wp-includes/category-template.php */
175           return apply_filters( 'the_category', '', $separator, $parents );
176      }
177
178      /**
179       * Filter the categories before building the category list.
180       *
181       * @since 4.4.0
182       *
183       * @param array    $categories An array of the post's categories.
184       * @param int|bool $post_id    ID of the post we're retrieving categories for. When `false`, we assume the
185       *                             current post in the loop.
186       */
187      $categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );
188
189      if ( empty( $categories ) ) {
190           /** This filter is documented in wp-includes/category-template.php */
191           return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
192      }
193
194      $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
195
196      $thelist = '';
197      if ( '' == $separator ) {
198           $thelist .= '<ul class="post-categories">';
199           foreach ( $categories as $category ) {
200                $thelist .= "\n\t<li>";
 
Line Code
245       * Filter the category or list of categories.
246       *
247       * @since 1.2.0
248       *
249       * @param array  $thelist   List of categories for the current post.
250       * @param string $separator Separator used between the categories.
251       * @param string $parents   How to display the category parents. Accepts 'multiple',
252       *                          'single', or empty.
253       */
254      return apply_filters( 'the_category', $thelist, $separator, $parents );
255 }
256
257 /**
258  * Check if the current post in within any of the given categories.
259  *
260  * The given categories are checked against the post's categories' term_ids, names and slugs.
261  * Categories given as integers will only be checked against the post's categories' term_ids.
262  *
263  * Prior to v2.5 of WordPress, category names were not supported.