<?php
/*
Plugin Name: META Relationship Links
Plugin URI: http://guff.szub.net/meta-relationship-links/
Description: Inserts head link tags on single post pages for start (home), next, prev (previous), first and last posts.
Version: R1.1
Author: Kaf Oseo
Author URI: http://szub.net
Copyright (c) 2005 Kaf Oseo (http://szub.net)
META Relationship Links is released under the GNU General Public
License (GPL) http://www.gnu.org/licenses/gpl.txt
This is a WordPress plugin (http://wordpress.org).
~Changelog:
R1.1 (23-Dec-2005)
Temporarily hide WP database errors on single posts (rel=prev/next
output) for invalid post queries.
*/
function meta_rel_links() {
global $post, $wpdb;
if(!is_home()) {
echo '<link rel="start" href="' . get_bloginfo('siteurl') . '" title="Home" />' . "\n";
}
$firstpost = @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date ASC LIMIT 1");
if($firstpost) {
$first_title = strip_tags(str_replace('"', '', $firstpost->post_title));
echo '<link rel="first" href="' . get_permalink($firstpost->ID) . '" title="' . $first_title. '" />' . "\n";
}
$lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
if($lastpost) {
$last_title = strip_tags(str_replace('"', '', $lastpost->post_title));
echo '<link rel="last" href="' . get_permalink($lastpost->ID) . '" title="' . $last_title. '" />' . "\n";
}
if(is_single()) {
global $wpdb, $wp_query;
$post = $wp_query->post;
$wpdb->hide_errors(); // hide errors on invalid post queries
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo '<link rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" />' . "\n";
}
$next_post = get_next_post();
if($next_post) {
$next_title = strip_tags(str_replace('"', '', $next_post->post_title));
echo '<link rel="next" href="' . get_permalink($next_post->ID) . '" title="' . $next_title. '" />' . "\n";
}
$wpdb->show_errors(); // turn errors back on
}
}
add_action('wp_head', 'meta_rel_links');
?>