Make WordPress Core


Ignore:
Timestamp:
01/19/2009 05:04:58 AM (16 years ago)
Author:
azaozz
Message:

Add support for automatic feed links in themes, props Viper007Bond, see #8878

File:
1 edited

Legend:

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

    r10356 r10377  
    13701370
    13711371/**
     1372 * Enable/disable automatic general feed link outputting.
     1373 *
     1374 * @since 2.8.0
     1375 *
     1376 * @param boolean $add Add or remove links. Defaults to true.
     1377 */
     1378function automatic_feed_links( $add = true ) {
     1379    if ( $add )
     1380        add_action( 'wp_head', 'feed_links', 2 );
     1381    else {
     1382        remove_action( 'wp_head', 'feed_links', 2 );
     1383        remove_action( 'wp_head', 'feed_links_extra', 3 );
     1384    }
     1385}
     1386
     1387/**
     1388 * Display the links to the general feeds.
     1389 *
     1390 * @since 2.8.0
     1391 *
     1392 * @param array $args Optional arguments.
     1393 */
     1394function feed_links( $args ) {
     1395    $defaults = array(
     1396        'seperator'   => _c('»|Seperator character feed titles in theme head'),
     1397        'rsstitle'    => __('%s Feed'),
     1398        'comstitle'   => __('%s Comments Feed'),
     1399    );
     1400
     1401    $args = wp_parse_args( $args, $defaults );
     1402
     1403    echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['rsstitle'], get_bloginfo('name') ) . '" href="' . get_feed_link() . "\" />\n";
     1404    echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['comstitle'], get_bloginfo('name') ) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
     1405}
     1406
     1407/**
     1408 * Display the links to the extra feeds such as category feeds.
     1409 *
     1410 * @since 2.8.0
     1411 *
     1412 * @param array $args Optional arguments.
     1413 */
     1414function feed_links_extra( $args ) {
     1415    $defaults = array(
     1416        'seperator'   => _c('&raquo;|Seperator character feed titles in theme head'),
     1417        'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
     1418        'cattitle'    => __('%1$s %2$s %3$s Category Feed'),
     1419        'tagtitle'    => __('%1$s %2$s %3$s Tag Feed'),
     1420        'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
     1421        'searchtitle' => __('%1$s %2$s Search Results for &quot;%3$s&quot; Feed'),
     1422    );
     1423
     1424    $args = wp_parse_args( $args, $defaults );
     1425
     1426    if ( is_single() || is_page() ) {
     1427        $post = &get_post( $id = 0 );
     1428        if ( comments_open() || pings_open() || $post->comment_count > 0 )
     1429            echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['singletitle'], get_bloginfo('name'), $args['seperator'], get_the_title() ) . '" href="' . get_post_comments_feed_link( $post->ID ) . "\" />\n";
     1430    }
     1431
     1432    elseif ( is_category() ) {
     1433        $cat_id = intval( get_query_var('cat') );
     1434        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['cattitle'], get_bloginfo('name'), $args['seperator'], get_cat_name( $cat_id ) ) . '" href="' . get_category_feed_link( $cat_id ) . "\" />\n";
     1435    }
     1436
     1437    elseif ( is_tag() ) {
     1438        $tag_id = intval( get_query_var('tag_id') );
     1439        $tag = get_tag( $tag_id );
     1440        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['tagtitle'], get_bloginfo('name'), $args['seperator'], $tag->name ) . '" href="' . get_tag_feed_link( $tag_id ) . "\" />\n";
     1441    }
     1442
     1443    elseif ( is_author() ) {
     1444        $author_id = intval( get_query_var('author') );
     1445        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['authortitle'], get_bloginfo('name'), $args['seperator'], get_author_name( $author_id ) ) . '" href="' . get_author_feed_link( $author_id ) . "\" />\n";
     1446    }
     1447
     1448    elseif ( is_search() ) {
     1449        echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['searchtitle'], get_bloginfo('name'), $args['seperator'], get_search_query() ) . '" href="' . get_search_feed_link() . "\" />\n";
     1450    }
     1451}
     1452
     1453/**
    13721454 * Display the link to the Really Simple Discovery service endpoint.
    13731455 *
Note: See TracChangeset for help on using the changeset viewer.