You mean something like this?
<?php
$link = get_post_meta($post->ID, 'your_custom_field', true);
if ($link){
echo 'Credit: <a href="$link">Mr. Blogs</a>';
}
?>
Thread Starter
twro
(@twro)
Yes, but could you show me how to change the ‘Mr. Blogs’ part as well each time using custom fields?
If that’s the case then you will need a custom field for the link/URL and a custom field for the link text.
<?php
$link = get_post_meta($post->ID, 'link_url', true);
$text = get_post_meta($post->ID, 'link_text', true);
if ($link){
echo 'Credit: <a href="$link">'.$text.'</a>';
}
?>
Thread Starter
twro
(@twro)
It comes up perfectly, but for some reason the link url is all messed up. It comes up with the blog post url and /$link after it.
What value do you have for your link_url custom field?
Oops,
<?php
$link = get_post_meta($post->ID, 'link_url', true);
$text = get_post_meta($post->ID, 'link_text', true);
if ($link){
echo 'Credit: <a href="'.$link .'">'.$text.'</a>';
}
?>
Thread Starter
twro
(@twro)
No dude, it now just has the url at the end of the post :(. I’m using link_url as the value.
your link_url custom field value needs to be http://www.domain.com
your link_text custom field value needs to be Mr Blogs (or whatever)
Following on from the above. Is there a way of allowing multiple links? I’m learning php so excuse the following attempt.
<?php
$links = get_post_meta($post->ID, 'linked_material_url', false);
$text = get_post_meta($post->ID, 'linked_material_text', false);
?>
<ul>
<?php foreach($links as $link) {
echo '<a href="$link">'.$text.'</a><br />';
} ?>
</ul>