Make WordPress Core

Changeset 5235


Ignore:
Timestamp:
04/10/2007 09:23:11 PM (19 years ago)
Author:
ryan
Message:

Change get_the_tags() to return an array of tags. Move tag list code to the_tags(). fixes #4123

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r5234 r5235  
    3939        }
    4040        return apply_filters('category_link', $catlink, $category_id);
    41 }
    42 
    43 function get_tag_link( $tag_id ) {
    44         global $wp_rewrite;
    45         $catlink = $wp_rewrite->get_tag_permastruct();
    46 
    47         $category = &get_category($tag_id);
    48         $category_nicename = $category->category_nicename;
    49 
    50         if ( empty($catlink) ) {
    51                 $file = get_option('home') . '/';
    52                 $catlink = $file . '?tag=' . $category_nicename;
    53         } else {
    54 
    55                 $catlink = str_replace('%tag%', $category_nicename, $catlink);
    56                 $catlink = get_option('home') . user_trailingslashit($catlink, 'category');
    57         }
    58         return apply_filters('tag_link', $catlink, $tag_id);
    5941}
    6042
     
    179161}
    180162
    181 function get_the_tags( $before, $sep, $after ) {
    182         global $post;
    183         if ( !$post )
    184                 return false; // in-the-loop function
    185 
    186         $tags = wp_get_post_tags( $post->ID );
    187         if ( empty( $tags ) )
    188                 return false;
    189        
    190         $return = $before;
    191         foreach ( $tags as $tag )
    192                 $tag_links[] = '<a href="' . get_tag_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
    193 
    194         $tag_links = join( $sep, $tag_links );
    195         $tag_links = apply_filters( 'the_tags', $tag_links );
    196         $return .= $tag_links;
    197 
    198         $return .= $after;
    199         return $return;
    200 }
    201 
    202 function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
    203         echo get_the_tags( $before, $sep, $after );
    204 }
    205 
    206163function category_description($category = 0) {
    207164        global $cat;
     
    410367}
    411368
     369//
     370// Tags
     371//
     372
     373function get_tag_link( $tag_id ) {
     374        global $wp_rewrite;
     375        $catlink = $wp_rewrite->get_tag_permastruct();
     376
     377        $category = &get_category($tag_id);
     378        $category_nicename = $category->category_nicename;
     379
     380        if ( empty($catlink) ) {
     381                $file = get_option('home') . '/';
     382                $catlink = $file . '?tag=' . $category_nicename;
     383        } else {
     384
     385                $catlink = str_replace('%tag%', $category_nicename, $catlink);
     386                $catlink = get_option('home') . user_trailingslashit($catlink, 'category');
     387        }
     388        return apply_filters('tag_link', $catlink, $tag_id);
     389}
     390
     391function get_the_tags( $id = 0 ) {
     392        global $post;
     393 
     394        $id = (int) $id;
     395
     396        if ( ! $id && ! in_the_loop() )
     397                return false; // in-the-loop function
     398 
     399        if ( !$id )
     400                $id = (int) $post->ID;
     401
     402        $tags = wp_get_post_tags( $id );
     403        $tags = apply_filters( 'get_the_tags', $tags );
     404        if ( empty( $tags ) )
     405                return false;
     406        return $tags;
     407}
     408
     409function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
     410        $tags = get_the_tags();
     411
     412        if ( empty( $tags ) )
     413                return false;
     414       
     415        $tag_list = $before;
     416        foreach ( $tags as $tag )
     417                $tag_links[] = '<a href="' . get_tag_link($tag->cat_ID) . '">' . $tag->cat_name . '</a>';
     418
     419        $tag_links = join( $sep, $tag_links );
     420        $tag_links = apply_filters( 'the_tags', $tag_links );
     421        $tag_list .= $tag_links;
     422
     423        $tag_list .= $after;
     424
     425        echo $tag_list;
     426}
     427
    412428?>
Note: See TracChangeset for help on using the changeset viewer.