adding a URL to a post meta

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

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
Add a comment  | 

2 Answers 2

Reset to default 2

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>';
}
?>

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

相关推荐

  • adding a URL to a post meta

    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

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信