Permalink target for recent post

The problem is that the functions the_title(), the_ID() etc. access the current post, which is the last post after the query has been handled completely.

Put the following either

  • in a text widget, wrapped in <?php and ?>, while having PHP execution enabled for text widgets (e.g., by using Exec-PHP and the like);
  • in a PHP Code Widget (again wrapped in <?php and ?>);
  • hard-coded into your sidebar.php (or whatever your sidebar template file may be named);
  • in your functions.php, wrapped in a function, then call the function wherever you want.

Share the Most Recent Post

// EDIT regarding your last comment:

<?php
    $su_link = $su_title = $su_href="";

    if (is_single()) {
        // We're showing a single blog post
        // => take the data and deal with it
        $su_link = get_permalink();
        $su_title = get_the_title();
    } elseif (is_home()) {
        // We're showing the 'home' archive
        // => take the first post's data and deal with it
        $ID = $GLOBALS['posts'][0]->ID;
        $su_link = get_permalink($ID);
        $su_title = get_the_title($ID);
    }

    if ('' !== $su_link) {
        // We have data
        // => generate the link
        $su_href="http://www.stumbleupon.com/submit?url=".urlencode($su_link).'&title=".urlencode($su_title);
    }
?>


<map name="sociallinks">
    <area name="stumble" shape="rect" coords="126,0,179,48" href="<?php echo $su_href; ?>" title="<?php echo $su_title; ?>" />
</map>