Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Post Title link to external URL in Autpfucos+ theme WordPress

  • SOLVED

I am looking to have the post title to be able to link to any external url needed. Currently it's in the standard wordpress setup, where the post title url is the permalink. I found several articles that hacks the permalink on the post title, however, the function.php page is also different in the Autofocus+ theme and the hack method did not apply.

Answers (3)

2010-08-04

Rashad Aliyev answers:

You should use permalink redirector plugin. That's very simple way.


Rashad Aliyev comments:

P.S: Use this plugin and without loosing your PageRank!

http://wordpress.org/extend/plugins/advanced-permalinks/

best regards,


Theresa C comments:

Hi Rashad,

Thank you for the link, but it seems like this plugin allow customization of the permalink which is still an internal url and I need to get the title to link to an external url. I am open to any other solution you may have as well :)


Rashad Aliyev comments:

Very Easy solution:

Find your <strong><?php the_title(); ?></strong> at your single.php , page.php or etc. and replace with like this code.

Then make an Custom Field that name in my example: <strong>external-link</strong>




<?php if( get_post_meta($post->ID, "external-link", true) ): ?>
<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">
<?php else: ?>
<a href="<?php the_permalink() ?>">
<?php endif; ?>
<?php the_title(); ?></a>




That's all! 100% will worked;)

If you've any problem with your integration you can get special support. I'm available.

best regards,





Rashad Aliyev comments:

@Agent Wordpress you searched something and told your solutions with some functions. But I made it myself and send it. That's my solutions and also I've enough experiences for making simple things..

@Theresa C; I hope you'll choose which is easy for you.

best regards..


Theresa C comments:

Hi Rashad,

I looked into the single.php and this is the code
<?php

// calling the header.php
get_header();

// action hook for placing content above #container
thematic_abovecontainer();

?>

<div id="container">
<div id="content">

<?php

the_post();

// create the navigation above the content
thematic_navigation_above();

// calling the widget area 'single-top'
get_sidebar('single-top');

// action hook creating the single post
thematic_singlepost();

// calling the widget area 'single-insert'
get_sidebar('single-insert');

// create the navigation below the content
thematic_navigation_below();

// calling the comments template
thematic_comments_template();

// calling the widget area 'single-bottom'
get_sidebar('single-bottom');

?>

</div><!-- #content -->
</div><!-- #container -->

<?php

// action hook for placing content below #container
thematic_belowcontainer();

// calling the standard sidebar
thematic_sidebar();

// calling footer.php
get_footer();

?>



However, I did find similar to the post title you said to replace in the Thematic Function php file, which looks like this http://wordpress.pastebin.com/3q2HReb6

There's also a separate theme function php file that looks like this http://wordpress.pastebin.com/SJmqZ1Lf

Please let me know where it is appropriate to paste the code?

Many thanks,
Theresa


Rashad Aliyev comments:

Hello again,

I made some changes on your functions.

(Which I get from this URL: http://wordpress.pastebin.com/3q2HReb6 )


Change it with your Thematic functions file.

P.S: Don't forget backup your current file and be sure that you're changing it with this one: http://wordpress.pastebin.com/3q2HReb6 .

Check it again and tell me what happened.. ;)


Best regards,



<?php

// Favorite Icon
function autofocus_favicon() { ?>
<link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/img/favicon.ico">
<?php }
add_action('wp_head', 'autofocus_favicon', 1);

// Add a Home link to your menu
function childtheme_menu_args($args) {
$args = array(
'show_home' => 'Home',
'sort_column' => 'menu_order',
'menu_class' => 'menu',
'echo' => true
);
return $args;
}
add_filter('wp_page_menu_args','childtheme_menu_args');

// Create Arrow Navigation
// - remove default navigation
function remove_thematic_actions() {
remove_action('thematic_navigation_above', 'thematic_nav_above', 2);
remove_action('thematic_navigation_below', 'thematic_nav_below', 2);
}
add_action('init','remove_thematic_actions');

// - add arrow navigation
function autofocus_nav_above() {
if (is_single()) { ?>
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php previous_post_link('%link', __('<span class="meta-nav">&larr;</span>', 'thematic')) ?></div>
<div class="nav-next"><?php next_post_link('%link', __('<span class="meta-nav">&rarr;</span>', 'thematic')) ?></div>
</div>

<?php } else { ?>
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&larr;</span>', 'thematic')) ?></div>
<div class="nav-next"><?php previous_posts_link(__('<span class="meta-nav">&rarr;</span>', 'thematic')) ?></div>
</div>

<?php } }
add_action('thematic_navigation_above', 'autofocus_nav_above', 2);

// Add arrows to the Post excerpt
function autofocus_readmore($text) {
// No arrows on the Home page excerpts
if (is_home() || is_feed()) {
return str_replace('[...]', ' &hellip;', $text);
} else {
return str_replace('[...]', ' &hellip; <a href="'.get_permalink().'" class="more-link">' . __('Read More ', 'thematic') . '<span class="excerpt-arrow">&rarr;</span></a>', $text);
} }
add_filter('get_the_excerpt', 'autofocus_readmore');

// Add New Excerpt Word Count
function autofocus_excerpt_length($length) {
// Add more words for the Archive pages
if (is_archive() || is_search()) {
return 45;
} else {
return 25;
} }
add_filter('excerpt_length', 'autofocus_excerpt_length');

// Show excerpts on Home pages and Archives
function autofocus_content($content) {
global $content;
if ( is_archive() || is_front_page() || is_search() ) {
$content= 'excerpt';
} else {
$content= 'full';
}
return $content;
}
add_filter('thematic_content', 'autofocus_content');

// Add <p> Tags to Excerpts
function autofocus_excerpt_autop() {
global $content;

if ( strtolower($content) == 'full' ) {
$post = get_the_content(more_text());
$post = apply_filters('the_content', $post);
$post = str_replace(']]>', ']]>', $post);

} elseif ( strtolower($content) == 'excerpt') {
$post = get_the_excerpt();

// add in the <p>
$post = wpautop($post);

} elseif ( strtolower($content) == 'none') {
} else {
$post = get_the_content(more_text());
$post = apply_filters('the_content', $post);
$post = str_replace(']]>', ']]>', $post);
}
return $post;
}
add_filter('thematic_post','autofocus_excerpt_autop');

// Add the Featured/Sticky Post section
function af_sticky_area() {
global $afoptions;
foreach ($afoptions as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

if( is_home() && !is_paged() ) { ?>

<?php if (get_option('sticky_posts')) { ?>
<?php
$sticky = get_option('sticky_posts');
$randomStickyNo = 0;
$randomStickyNo = (rand()%(count($sticky)));
$postno = $sticky[($randomStickyNo)];
$temp = $stickyquery;
$stickyquery = null;
$stickyquery = new WP_Query();
$stickyquery->query('orderby=rand&showposts=1&p=' . $postno); ?>

<?php while ($stickyquery->have_posts()) : $stickyquery->the_post(); $do_not_duplicate = $post->ID; ?>
<div id="sticky-feature">
<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class(); ?> sticky-feature-post">

<?php echo thematic_postheader_posttitle(); ?>

<div class="entry-meta">
<?php if ($af_show_post_title == 'false') { ?>
<span class="entry-date"><a href="<?php the_permalink() ?>" class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>" rel="bookmark"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time('j M') ?></abbr></a></span>
<?php } elseif ($af_show_post_title == 'true') { ?>
<span class="entry-title">

<?php if( get_post_meta($post->ID, "external-link", true) ): ?>

<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">

<?php else: ?>

<a href="<?php the_permalink() ?>">

<?php endif; ?>

<?php the_title(); ?></a> </span>
<?php } ?>
</div>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="post-image-container"><?php the_post_thumbnail('aflarge'); ?></a>
<?php } else { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="post-image-container"><?php the_post_image('aflarge'); ?></a>
<?php } ?>

<div class="entry-content">
<?php the_excerpt(); ?>
</div>

<div class="entry-utility">
<?php edit_post_link(__('Edit', 'thematic'), "\t\n\t\t\t\t\t<span class=\"edit-link\">", "</span>\n"); ?>
</div><!-- .entry-utility -->
</div>
</div><!-- #sticky-feature -->

<?php endwhile; ?>

<?php query_posts(array(
'post__not_in' =>get_option('sticky_posts'),
'caller_get_posts' => 1,
'paged' => $paged,
)); ?>

<?php } ?>

<?php } else { ?>

<?php query_posts(array(
'post__not_in' =>get_option('sticky_posts'),
'caller_get_posts' => 1,
'exclude' => $postno,
'paged' => $paged,
)); ?>

<?php } ?>

<?php }
add_action('thematic_above_indexloop','af_sticky_area');

// Custom Post Header
function autofocus_postheader() {
global $post;
global $afoptions;
foreach ($afoptions as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}

$data = get_post_meta( $post->ID, 'autofocus', true );

if (is_page()) { ?>
<h2 class="entry-title"><?php if( get_post_meta($post->ID, "external-link", true) ): ?>

<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">

<?php else: ?>

<a href="<?php the_permalink() ?>">

<?php endif; ?>

<?php the_title(); ?></a>
</h2>

<?php } elseif (is_404()) { ?>
<h2 class="entry-title">Not Found</h2>

<?php } elseif (is_single()) { ?>

<?php if ($data[ 'videoembed_value' ]) { ?>
<div class="post-video-container">
<?php $af_video_url = $data[ 'videoembed_value' ]; $content = apply_filters('the_content', '<span>[embed width="800" height="600"]'.$af_video_url.'[/embed]</span>'); echo $content; ?>
</div>

<?php } else { ?>
<div class="post-image-container">
<?php if ($data[ 'copyright_value' ]) { ?>
<span class="photo-credit"><?php echo $data[ 'copyright_value' ]; ?></span>
<?php } else { ?>
<?php autofocus_credit(); ?>
<?php } ?>

<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('single-post-thumbnail'); ?>

<?php } else { ?>
<?php the_post_image('afsingle'); ?>

<?php } ?>
</div>
<?php } ?>

<h2 class="entry-title"><?php if( get_post_meta($post->ID, "external-link", true) ): ?>

<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">

<?php else: ?>

<a href="<?php the_permalink() ?>">

<?php endif; ?>

<?php the_title(); ?></a>
</h2>

<?php } elseif (is_archive() || is_search()) { ?>

<?php if ( $post->post_type == 'post' ) { // Hide entry utility on searches ?>

<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="post-image-container"><?php the_post_thumbnail('archive-thumbnail'); ?></a>
<?php } else { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="post-image-container"><?php the_post_image('afthumb'); ?></a>
<?php } ?>

<?php } ?>

<h3 class="entry-title"><?php if( get_post_meta($post->ID, "external-link", true) ): ?>

<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">

<?php else: ?>

<a href="<?php the_permalink() ?>">

<?php endif; ?>

<?php the_title(); ?></a>
</h3>

<?php } else { ?>
<h2 class="entry-title"><?php if( get_post_meta($post->ID, "external-link", true) ): ?>

<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">

<?php else: ?>

<a href="<?php the_permalink() ?>">

<?php endif; ?>

<?php the_title(); ?></a>
</h2>

<?php } }
add_filter ('thematic_postheader_posttitle', 'autofocus_postheader');

// AutoFocus Post Meta
function autofocus_postmeta() {
global $post;
global $afoptions;
foreach ($afoptions as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}

$data = get_post_meta( $post->ID, 'autofocus', true );

if (is_single()) { ?>
<div class="entry-meta">
<span class="entry-date"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time('j M') ?></abbr></span>
<?php if ($af_show_exif_data == 'true' && has_post_thumbnail() && ($data[ 'videoembed_value' ] == '')) { ?>
<span class="exif-data"><a href="<?php echo exif_link(); ?>/#exif-data"><?php _e('View Exif Data', 'thematic') ?></a></span>
<?php } ?>
<span class="cat-links"><?php printf(__('Filed under %s.', 'thematic'), get_the_category_list(', ')) ?></span>
<?php echo get_the_tag_list("<span class=\"tag-links\"> Tagged ",', ','.</span>'); ?>
<?php echo autofocus_postconnect(); ?>
<?php edit_post_link(__('Edit', 'thematic'), "\t\n\t\t\t\t\t<span class=\"edit-link\">", "</span>\n"); ?>
</div>

<?php } elseif (is_home()) { ?>

<?php if ($af_show_post_title == 'false') { ?>
<div class="entry-meta">
<span class="entry-date"><a href="<?php the_permalink() ?>" class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>" rel="bookmark"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time('j M') ?></abbr></a></span>
</div>

<?php } elseif ($af_show_post_title == 'true') { ?>
<div class="entry-meta">
<span class="entry-title"><?php if( get_post_meta($post->ID, "external-link", true) ): ?>

<a href="<?php echo get_post_meta($post->ID, 'external-link', true); ?>">

<?php else: ?>

<a href="<?php the_permalink() ?>">

<?php endif; ?>

<?php the_title(); ?></a>
</span>
</div>

<?php } ?>

<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="post-image-container"><?php the_post_thumbnail('front-page-thumbnail'); ?></a>
<?php } else { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="post-image-container"><?php the_post_image('aflarge'); ?></a>
<?php } ?>

<?php } else { ?>
<div class="entry-meta">
<span class="entry-date"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time('j M') ?></abbr></span>
<span class="cat-links"><?php printf(__('Filed under %s.', 'thematic'), get_the_category_list(', ')) ?></span>
<span class="comments-link"><?php comments_popup_link(__('No comments.', 'thematic'), __('1 Comment.', 'thematic'), __('% Comments.', 'thematic'), '', '') ?></span>
<?php edit_post_link(__('Edit', 'thematic'), "\t\n\t\t\t\t\t<span class=\"edit-link\">", "</span>\n"); ?>
</div>

<?php } }
add_filter ('thematic_postheader_postmeta', 'autofocus_postmeta');

// AutoFocus Post Footer
function autofocus_postfooter() {
global $post;

if (is_single() || is_page()) {
if (is_sidebar_active('single-sidebar')) {
echo thematic_before_widget_area('single-sidebar');
dynamic_sidebar('single-sidebar');
echo thematic_after_widget_area('single-sidebar');
} ?>

<?php } elseif (is_home()) { ?>
<div class="entry-utility">
<?php edit_post_link(__('Edit', 'thematic'), "\t\n\t\t\t\t\t<span class=\"edit-link\">", "</span>\n"); ?>
</div><!-- .entry-utility -->

<?php } else {
// Show nothing
}
}
add_filter ('thematic_postfooter', 'autofocus_postfooter');

// AutoFocus Post Connect
function autofocus_postconnect() { ?>
<?php printf(__('<span class="bookmark">Bookmark the <a href="%1$s" title="Permalink to %2$s" rel="bookmark">permalink</a>.</span>', 'thematic'),
get_permalink(),
wp_specialchars(get_the_title(), 'double') ) ?>
<?php if ((comments_open()) && (pings_open())) : // Comments and trackbacks open ?>
<?php printf(__('<span class="post-a-comment"><a class="comment-link" href="#respond" title="Post a comment">Post a comment</a>.</span> <span class="trackback">Leave a <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback (URL)</a>.</span>', 'thematic'), get_trackback_url()) ?>
<?php elseif (!(comments_open()) && (pings_open())) : // Only trackbacks open ?>
<?php printf(__('<span class="trackback">Leave a <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback (URL)</a>.</span>', 'thematic'), get_trackback_url()) ?>
<?php elseif ((comments_open()) && !(pings_open())) : // Only comments open ?>
<?php printf(__('<span class="post-a-comment"><a class="comment-link" href="#respond" title="Post a comment">Post a comment</a>.</span>', 'thematic')) ?>
<?php elseif (!(comments_open()) && !(pings_open())) : // Comments and trackbacks closed ?>
<?php // Show nothing ?>
<?php endif; ?>
<?php }
// add_filter('thematic_postfooter_postconnect', 'autofocus_postconnect');

// Navigation Below.
function autofocus_nav_below() {
if (is_single()) { ?>
<div id="nav-below" class="navigation">
<h3><?php _e('Browse', 'thematic') ?></h3>
<?php
$previouspost = get_previous_post($in_same_cat, $excluded_categories);
if ($previouspost != null) {

echo '<div class="nav-previous">';
previous_post_link('<span class="meta-nav">&larr;</span> Older: %link');
echo '<div class="nav-excerpt">';
previous_post_excerpt();
echo '</div></div>';
} ?>

<?php
$nextpost = get_next_post($in_same_cat, $excluded_categories);
if ($nextpost != null) {

echo '<div class="nav-next">';
next_post_link('Newer: %link <span class="meta-nav">&rarr;</span>');
echo '<div class="nav-excerpt">';
next_post_excerpt();
echo '</div></div>';
} ?>

</div><!-- #nav-below -->

<?php } elseif (browser_ie6() && is_home() ) { ?>

<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&larr;</span>', 'thematic')) ?></div>
<div class="nav-next"><?php previous_posts_link(__('<span class="meta-nav">&rarr;</span>', 'thematic')) ?></div>
</div>

<?php } }
add_action('thematic_navigation_below', 'autofocus_nav_below', 2);

// UNregister non-used sidebars
function childtheme_sidebars_init() {

// Register the 4th Subsidairy Sidebar
register_sidebar(array(
'name' => '4th Subsidiary Aside',
'id' => '4th-subsidiary-aside',
'description' => __('The 4th widget area in the footer.', 'thematic'),
'before_widget' => thematic_before_widget(),
'after_widget' => thematic_after_widget(),
'before_title' => thematic_before_title(),
'after_title' => thematic_after_title(),
));

// Register the Single Page Sidebar
register_sidebar(array(
'name' => 'Single Page Sidebar',
'id' => 'single-sidebar',
'description' => __('This widget area shows up under the post meta on Single Posts and Pages.', 'thematic'),
'before_widget' => thematic_before_widget(),
'after_widget' => thematic_after_widget(),
'before_title' => thematic_before_title(),
'after_title' => thematic_after_title(),
));

unregister_sidebar('primary-aside');
unregister_sidebar('secondary-aside');
unregister_sidebar('index-top');
unregister_sidebar('index-insert');
unregister_sidebar('index-bottom');
unregister_sidebar('single-top');
unregister_sidebar('single-insert');
unregister_sidebar('single-bottom');
unregister_sidebar('page-top');
unregister_sidebar('page-bottom');
}
add_action( 'init', 'childtheme_sidebars_init',20 );

// Add 4th Sidebar Area
function add_fourth_sidebar() {
if (is_sidebar_active('4th-subsidiary-aside')) {
echo thematic_before_widget_area('4th-subsidiary-aside');
dynamic_sidebar('4th-subsidiary-aside');
echo thematic_after_widget_area('4th-subsidiary-aside');
}
}
add_action('thematic_after_third_sub','add_fourth_sidebar');

// Add a link to the footer for credit
function childtheme_theme_link($themelink) {
$loginlinkage = thmfooter_login_link();
return '<a class="child-theme-link" href="http://fthrwght.com/autofocus/" title="AutoFocus Pro" rel="theme">AutoFocus Pro Child Theme</a> &amp; the ' . $themelink . '. ' . $loginlinkage;
}
add_filter('thematic_theme_link', 'childtheme_theme_link');

// Adds commented credit
function author_credit() { ?>
<!-- Design based on AutoFocus Pro by Allan Cole for http://fthrwght.com/autofocusplus -->
<?php }
add_action('wp_footer','author_credit');

?>





Rashad Aliyev comments:

After this change When you're saving post Use the Custom Field like this: