You could simply link an <h2> tag inside your content and omit the the_title(); from the loop or, as you stated, you could link the the_title() with a custom field.
You could call your custom field “link” and use it this way:
<?php $field_name="link"; $field_value = get_post_meta($post->ID, $field_name, true); ?>
then, to link the title
<a href="<?php echo $field_value; ?>"><?php the_title(); ?></a>
This, of course, assumes your “link” custom field contains a fully qualified url.
Thread Starter
fath
(@fath)
Hey, it works perfectly. Thanks! 🙂
I needed this info for another purpose; great! Thanks.
Hi All,
First of all thanks for the helpful post here.
I am trying to use custom field to change the ‘read more’ links of my posts on the homepage of my blog to link through to either individual pages or to the post page.
So far I managed to assign the custom fields value (url) to the link of the post but I cannot get the default value back.
I guess my main problem is letting $field_value be the_permalink() if there is no value in the custom field with the key link
Please let me know if you have any idea how to fix this.
What I have:
an if statement to determine if there is a custom field:
if($field_name=”link”){
$field_value = $field_value = get_post_meta($post->ID, $field_name, true);
}else {
$field_value = the_permalink();
}
The value of $field_value is being read out in the link:
“<?php echo $field_value; ?>”
I think this is the answer to your question?
I have got this, so only if I assign a url to a custom field called “alamy” does the whole thing show up:
<?php if(get_post_meta($post->ID, "alamy", true)): { ?>
<?php $field_name="alamy"; $field_value = get_post_meta($post->ID, $field_name, true); ?>
<a href="<?php echo $field_value; ?>" target="_blank">Buy this image at Alamy</a>
<?php ; } endif ?>
It seems to work. Thanks for the solution in this post. It saved me a whole afternoon. Or it would have if I’d found it earlier!