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

git-svn-id: http://svn.automattic.com/wordpress/trunk@10377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-01-19 05:04:58 +00:00
parent 6f0c0a1092
commit 3949fb7e90
14 changed files with 126 additions and 20 deletions

View File

@ -3,6 +3,9 @@
* @package WordPress
* @subpackage Classic_Theme
*/
automatic_feed_links();
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',

View File

@ -16,10 +16,6 @@
@import url( <?php bloginfo('stylesheet_url'); ?> );
</style>
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php wp_get_archives('type=monthly&format=link'); ?>
<?php //comments_popup_script(); // off by default ?>

View File

@ -4,13 +4,16 @@
* @subpackage Default_Theme
*/
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
automatic_feed_links();
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
/** @ignore */
function kubrick_head() {

View File

@ -13,8 +13,6 @@
<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<style type="text/css" media="screen">

View File

@ -164,6 +164,7 @@ add_filter( 'editable_slug', 'urldecode' );
add_filter('atom_service_url','atom_service_url_filter');
// Actions
add_action('wp_head', 'feed_links_extra', 3);
add_action('wp_head', 'rsd_link');
add_action('wp_head', 'wlwmanifest_link');
add_action('wp_head', 'locale_stylesheet');

View File

@ -5,7 +5,7 @@
* @package WordPress
*/
header('Content-Type: application/atom+xml; charset=' . get_option('blog_charset'), true);
header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '" ?' . '>';
?>
<feed

View File

@ -5,7 +5,7 @@
* @package WordPress
*/
header('Content-Type: application/atom+xml; charset=' . get_option('blog_charset'), true);
header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
?>

View File

@ -5,7 +5,7 @@
* @package WordPress
*/
header('Content-Type: application/rdf+xml; charset=' . get_option('blog_charset'), true);
header('Content-Type: ' . feed_content_type('rdf') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
?>

View File

@ -5,7 +5,7 @@
* @package WordPress
*/
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
header('Content-Type: ' . feed_content_type('rss') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
?>

View File

@ -5,7 +5,7 @@
* @package WordPress
*/
header('Content-Type: text/xml;charset=' . get_option('blog_charset'), true);
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>

View File

@ -5,7 +5,7 @@
* @package WordPress
*/
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
?>

View File

@ -508,4 +508,27 @@ function self_link() {
);
}
/**
* Return the content type for specified feed type.
*
* @package WordPress
* @subpackage Feed
* @since 2.8.0
*/
function feed_content_type( $type = '' ) {
if ( empty($type) )
$type = get_default_feed();
$types = array(
'rss' => 'application/rss+xml',
'rss2' => 'application/rss+xml',
'atom' => 'application/atom+xml',
'rdf' => 'application/rdf+xml',
);
$content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream';
return apply_filters( 'feed_content_type', $content_type, $type );
}
?>

View File

@ -1368,6 +1368,88 @@ function wp_footer() {
do_action('wp_footer');
}
/**
* Enable/disable automatic general feed link outputting.
*
* @since 2.8.0
*
* @param boolean $add Add or remove links. Defaults to true.
*/
function automatic_feed_links( $add = true ) {
if ( $add )
add_action( 'wp_head', 'feed_links', 2 );
else {
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
}
}
/**
* Display the links to the general feeds.
*
* @since 2.8.0
*
* @param array $args Optional arguments.
*/
function feed_links( $args ) {
$defaults = array(
'seperator' => _c('&raquo;|Seperator character feed titles in theme head'),
'rsstitle' => __('%s Feed'),
'comstitle' => __('%s Comments Feed'),
);
$args = wp_parse_args( $args, $defaults );
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['rsstitle'], get_bloginfo('name') ) . '" href="' . get_feed_link() . "\" />\n";
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . sprintf( $args['comstitle'], get_bloginfo('name') ) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
}
/**
* Display the links to the extra feeds such as category feeds.
*
* @since 2.8.0
*
* @param array $args Optional arguments.
*/
function feed_links_extra( $args ) {
$defaults = array(
'seperator' => _c('&raquo;|Seperator character feed titles in theme head'),
'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
'cattitle' => __('%1$s %2$s %3$s Category Feed'),
'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
'searchtitle' => __('%1$s %2$s Search Results for &quot;%3$s&quot; Feed'),
);
$args = wp_parse_args( $args, $defaults );
if ( is_single() || is_page() ) {
$post = &get_post( $id = 0 );
if ( comments_open() || pings_open() || $post->comment_count > 0 )
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";
}
elseif ( is_category() ) {
$cat_id = intval( get_query_var('cat') );
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";
}
elseif ( is_tag() ) {
$tag_id = intval( get_query_var('tag_id') );
$tag = get_tag( $tag_id );
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";
}
elseif ( is_author() ) {
$author_id = intval( get_query_var('author') );
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";
}
elseif ( is_search() ) {
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";
}
}
/**
* Display the link to the Really Simple Discovery service endpoint.
*

View File

@ -507,7 +507,7 @@ function get_category_feed_link($cat_id, $feed = '') {
$permalink_structure = get_option('permalink_structure');
if ( '' == $permalink_structure ) {
$link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
$link = trailingslashit( get_option('home') ) . "?feed=$feed&amp;cat=" . $cat_id;
} else {
$link = get_category_link($cat_id);
if( $feed == get_default_feed() )