Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

OK, a pretty dorky question, but I am new to PHP so bear with me.

How would I add an a href link to the code below so the custom meta field is linked on the front-end?

  <?php if(get_post_meta($post->ID, "leetpress_website", true)) { ?>
    <div class="pros"><p><strong>Movie Website:  </strong>
<?php echo get_post_meta($post->ID, "leetpress_website", true); ?></p></div>
<?php } ?>

Thanks for putting up with my dorky-ness...

UPDATE: Got it working! Thanks for the help pointing me in the right direction Bainternet!

<?php if(get_post_meta($post->ID, "leetpress_website", true)) { echo '<div class="pros"><p><strong>Movie Website:  </strong><a href="'.get_post_meta($post->ID, "leetpress_website", true).'" target="_blank">'.get_post_meta($post->ID, "leetpress_website", true).'</a></p></div>'; } ?>
share|improve this question
    
Monique, it is not necessary that you update your question with the answer you got. You can just mark Bainternet's answer as correct and eventually thanks him, or comment his answer with your implementation details/corrections. –  Drake May 18 '11 at 9:00
add comment

2 Answers

use another custom field with the URL and call it something like `leetpress_website_url' then change your code to this:

<?php if(get_post_meta($post->ID, "leetpress_website", true)) { 
    echo '<div class="pros"><p><strong>Movie Website:  </strong><a href="'.get_post_meta($post->ID, "leetpress_website_url", true).'">'.
    get_post_meta($post->ID, "leetpress_website", true).'</a></p></div>';
} ?>
share|improve this answer
    
Hello Bainternet! Your code is what I am after! Although it is currently linking back to the post and not to the external URL. (Maybe I didn't mention that part in my original question)Please view the live link to see what I mean: moxidesign.com/dev_chad/movies/soul-surfer –  Monique Anderson May 17 '11 at 18:26
    
Got it working! Thanks for the help pointing me in the right direction! –  Monique Anderson May 17 '11 at 19:15
add comment

It looks like something happened to the code you pasted, it's not complete, but here's an example of a meta field in an href:

<?php
$mylink = get_post_meta($post->ID, 'leetpress_website', true);
if($mylink){
?>
    <a href="<?php echo $mylink ?>" title="Movie Website">Movie Website</a>
<?php
}
?>

Edit- ok, Bainternet edited your code, see his answer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.