Make WordPress Core

Ticket #9291: feed_links_extra_DRY.patch

File feed_links_extra_DRY.patch, 3.0 KB (added by scribu, 17 years ago)
  • wp-includes/general-template.php

     
    14441444
    14451445        if ( is_single() || is_page() ) {
    14461446                $post = &get_post( $id = 0 );
    1447                 if ( comments_open() || pings_open() || $post->comment_count > 0 )
    1448                         echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['singletitle'], get_bloginfo('name'), $args['seperator'], wp_specialchars( get_the_title() ) )) . '" href="' . get_post_comments_feed_link( $post->ID ) . "\" />\n";
     1447
     1448                if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
     1449                        $title = attribute_escape(sprintf( $args['singletitle'], get_bloginfo('name'), $args['seperator'], wp_specialchars( get_the_title() ) ));
     1450                        $href = get_post_comments_feed_link( $post->ID );
     1451                }
    14491452        }
    14501453
    14511454        elseif ( is_category() ) {
    14521455                $cat_id = intval( get_query_var('cat') );
    1453                 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['cattitle'], get_bloginfo('name'), $args['seperator'], get_cat_name( $cat_id ) )) . '" href="' . get_category_feed_link( $cat_id ) . "\" />\n";
     1456
     1457                $title = attribute_escape(sprintf( $args['cattitle'], get_bloginfo('name'), $args['seperator'], get_cat_name( $cat_id ) ));
     1458                $href = get_category_feed_link( $cat_id );
    14541459        }
    14551460
    14561461        elseif ( is_tag() ) {
    14571462                $tag_id = intval( get_query_var('tag_id') );
    14581463                $tag = get_tag( $tag_id );
    1459                 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['seperator'], $tag->name )) . '" href="' . get_tag_feed_link( $tag_id ) . "\" />\n";
     1464
     1465                $title = attribute_escape(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['seperator'], $tag->name ));
     1466                $href = get_tag_feed_link( $tag_id );
    14601467        }
    14611468
    14621469        elseif ( is_author() ) {
    14631470                $author_id = intval( get_query_var('author') );
    1464                 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['authortitle'], get_bloginfo('name'), $args['seperator'], get_author_name( $author_id ) )) . '" href="' . get_author_feed_link( $author_id ) . "\" />\n";
     1471
     1472                $title = attribute_escape(sprintf( $args['authortitle'], get_bloginfo('name'), $args['seperator'], get_author_name( $author_id ) ));
     1473                $href = get_author_feed_link( $author_id );
    14651474        }
    14661475
    14671476        elseif ( is_search() ) {
    1468                 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . attribute_escape(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['seperator'], get_search_query() )) . '" href="' . get_search_feed_link() . "\" />\n";
     1477                $title = attribute_escape(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['seperator'], get_search_query() ));
     1478                $href = get_search_feed_link();
    14691479        }
     1480
     1481        if ( empty($title) || empty($href) )
     1482                return;
     1483
     1484        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . $title . '" href="' . $href . "\" />\n";
    14701485}
    14711486
    14721487/**