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>';
}
?>
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
edited Aug 22, 2019 at 22:22
alo Malbarez
4451 gold badge6 silver badges7 bronze badges
asked May 17, 2011 at 17:35
Monique AndersonMonique Anderson
211 silver badge3 bronze badges
1
- 1 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 Commented May 18, 2011 at 9:00
2 Answers
Reset to default 2Use 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>';
}
?>
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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745224005a4617377.html
评论列表(0条)