Return to Snippet

Revision: 23114
at January 30, 2010 13:41 by maryann


Initial Code
// function
function print_post_title() {
global $post;
    $thePostID = $post->ID;
    $post_id = get_post($thePostID);
    $title = $post_id->post_title;
    $perm = get_permalink($post_id);
    $post_keys = array(); $post_val = array();
    $post_keys = get_post_custom_keys($thePostID);

    if (!empty($post_keys)) {
foreach ($post_keys as $pkey) {
if ($pkey=='title_url') {
$post_val = get_post_custom_values($pkey);
}
}
if (empty($post_val)) {
$link = $perm;
} else {
$link = $post_val[0];
}
    } else {
$link = $perm;
    }
    echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
}

// template tag

<?php print_post_title() ?>

Initial URL


Initial Description
Now whenever you want to share an external URL, add a custom field to your post namedtitle_url and set its value as the URL of the resource.

Initial Title
Link title to external link

Initial Tags
wordpress

Initial Language
PHP