Make WordPress Core


Ignore:
Timestamp:
05/17/2010 04:21:12 PM (14 years ago)
Author:
ryan
Message:

Introduce get_term_feed_link(). Use it in wp_list_categories(). Props blepoxp. see #13058

File:
1 edited

Legend:

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

    r14702 r14711  
    569569*/
    570570function get_category_feed_link($cat_id, $feed = '') {
    571     $cat_id = (int) $cat_id;
    572 
    573     $category = get_category($cat_id);
    574 
    575     if ( empty($category) || is_wp_error($category) )
     571    return get_term_feed_link($cat_id, 'category', $feed);
     572}
     573
     574/**
     575 * Retrieve the feed link for a taxonomy.
     576 *
     577 * Returns a link to the feed for all post in a given term. A specific feed
     578 * can be requested or left blank to get the default feed.
     579 *
     580 * @since 3.0
     581 *
     582 * @param int $term_id ID of a category.
     583 * @param string $taxonomy Optional. Taxonomy of $term_id
     584 * @param string $feed Optional. Feed type.
     585 * @return string Link to the feed for the taxonomy specified by $term_id and $taxonomy.
     586*/
     587function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {
     588    global $wp_rewrite;
     589   
     590    $term_id = ( int ) $term_id;
     591
     592    $term = get_term( $term_id, $taxonomy  );
     593   
     594    if ( empty( $term ) || is_wp_error( $term ) )
    576595        return false;
    577596
    578     if ( empty($feed) )
     597    if ( empty( $feed ) )
    579598        $feed = get_default_feed();
    580599
    581     $permalink_structure = get_option('permalink_structure');
     600    $permalink_structure = get_option( 'permalink_structure' );
    582601
    583602    if ( '' == $permalink_structure ) {
    584         $link = home_url("?feed=$feed&cat=" . $cat_id);
     603        if ( 'category' == $taxonomy ) {
     604            $link = home_url("?feed=$feed&cat=$term_id");
     605        }
     606        elseif ( 'post_tag' == $taxonomy ) {
     607            $link = home_url("?feed=$feed&tag=$term->slug");
     608        } else {
     609            $t = get_taxonomy( $taxonomy );
     610            $link = home_url("?feed=$feed&$t->query_var=$term->slug");
     611        }
    585612    } else {
    586         $link = get_category_link($cat_id);
    587         if( $feed == get_default_feed() )
    588             $feed_link = 'feed';
    589         else
    590             $feed_link = "feed/$feed";
    591 
    592         $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
    593     }
    594 
    595     $link = apply_filters('category_feed_link', $link, $feed);
    596 
    597     return $link;
    598 }
    599 
    600 /**
    601  * Retrieve permalink for feed of tag.
    602  *
    603  * @since 2.3.0
    604  *
    605  * @param int $tag_id Tag ID.
    606  * @param string $feed Optional. Feed type.
    607  * @return string
    608  */
    609 function get_tag_feed_link($tag_id, $feed = '') {
    610     $tag_id = (int) $tag_id;
    611 
    612     $tag = get_tag($tag_id);
    613 
    614     if ( empty($tag) || is_wp_error($tag) )
    615         return false;
    616 
    617     $permalink_structure = get_option('permalink_structure');
    618 
    619     if ( empty($feed) )
    620         $feed = get_default_feed();
    621 
    622     if ( '' == $permalink_structure ) {
    623         $link = home_url("?feed=$feed&tag=" . $tag->slug);
    624     } else {
    625         $link = get_tag_link($tag->term_id);
     613        $link = get_term_link( $term_id, $term->taxonomy );
    626614        if ( $feed == get_default_feed() )
    627615            $feed_link = 'feed';
    628616        else
    629617            $feed_link = "feed/$feed";
    630         $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
    631     }
    632 
    633     $link = apply_filters('tag_feed_link', $link, $feed);
     618
     619        $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
     620    }
     621
     622    if ( 'category' == $taxonomy )
     623        $link = apply_filters( 'category_feed_link', $link, $feed );
     624    elseif ( 'post_tag' == $taxonomy )
     625        $link = apply_filters( 'category_feed_link', $link, $feed );
     626    else
     627        $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );
     628   
    634629
    635630    return $link;
     631}
     632
     633/**
     634 * Retrieve permalink for feed of tag.
     635 *
     636 * @since 2.3.0
     637 *
     638 * @param int $tag_id Tag ID.
     639 * @param string $feed Optional. Feed type.
     640 * @return string
     641 */
     642function get_tag_feed_link($tag_id, $feed = '') {
     643    return get_term_feed_link($tag_id, 'post_tag', $feed);
    636644}
    637645
Note: See TracChangeset for help on using the changeset viewer.