the_shortlink(). Props miqrogroove. fixes #10640

git-svn-id: http://svn.automattic.com/wordpress/trunk@13683 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-03-12 16:08:37 +00:00
parent aa92bfad14
commit 97e3559079
1 changed files with 31 additions and 2 deletions

View File

@ -2081,7 +2081,7 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
$shortlink = '';
// Return p= link for posts.
if ( !empty($post_id) ) {
if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
$post = get_post($post_id);
if ( isset($post->post_type) && 'post' == $post->post_type )
$shortlink = home_url('?p=' . $post->ID);
@ -2105,7 +2105,7 @@ function wp_shortlink_wp_head() {
if ( empty($shortlink) )
return;
echo '<link rel="shortlink" href="' . $shortlink . '" />';
echo "<link rel='shortlink' href='" . $shortlink . "' />\n";
}
/**
@ -2129,4 +2129,33 @@ function wp_shortlink_header() {
header('Link: <' . $shortlink . '>; rel=shortlink', false);
}
/**
* Display the Short Link for a Post
*
* Must be called from inside "The Loop"
*
* Call like the_shortlink(__('Shortlinkage FTW'))
*
* @since 3.0.0
*
* @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
* @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
* @param string $before Optional HTML to display before the link.
* @param string $before Optional HTML to display after the link.
*/
function the_shortlink($text = '', $title = '', $before = '', $after = '') {
global $post;
if ( empty($text) )
$text = __('This is the short link.');
if ( empty($title) )
$title = the_title_attribute( array('echo' => FALSE) );
$shortlink = wp_get_shortlink($post->ID);
if ( !empty($shortlink) )
echo "$before<a rel='shortlink' href='$shortlink' title='$title'>$text</a>$after";
}
?>