How to correctly write this code?

Discussion in 'PHP' started by caligrafx, Dec 7, 2011.

  1. #1
    I am looking for the correct why to right this code. The code I have shows up with my website address in front and I just need this to be a _blank target link to open!

    Shows up like this: http://www.mysite.com/folder/folder/page/http://www.linkineed.com
    Just need: http://www.linkineed.com

    Thanks,
    Adam

    <?php if($link != '') : ?>
    	        <li class="link clear">
                <button class="button"><a target="_blank" href="<?php echo $link; ?>"><?php _e('Download File', 'author'); ?></a></button>
    	        </li>
    	        <?php endif; ?>
    Code (markup):
     
    Last edited: Dec 7, 2011
    caligrafx, Dec 7, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    please tell us the contents of $link and <?php _e('Download File', 'author'); ?>
     
    EricBruggema, Dec 8, 2011 IP
  3. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3

    Well, I would guess that the contents of the $link would be the website page directory and than the "<?php _e('Download File', 'author'); ?>" would be the text field in the post editor that I write, but I am not 100% sure about that.
     
    caligrafx, Dec 8, 2011 IP
  4. kasun0777

    kasun0777 Well-Known Member

    Messages:
    355
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #4
    where are u got $link variable ??
     
    kasun0777, Dec 8, 2011 IP
  5. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #5
    Well, I found this code on the same page, does this help?

    <?php
          $caption = get_post_meta(get_the_ID(), 'portfolio_caption', TRUE);
          $link = get_post_meta(get_the_ID(), 'portfolio_link', TRUE);
    ?>
    Code (markup):
     
    caligrafx, Dec 9, 2011 IP
  6. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #6
    yes, but not if we don't know the content (use print_r($caption) or print_r($link) to display the results)

    but i think if you remove the $link part you'll get the correct writen domain name!
     
    EricBruggema, Dec 10, 2011 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    Change the code to
    
    <?php if($link != '') : ?>
                 <li class="link clear">
                 <button class="button"><a target="_blank" href="<?php echo $link; ?>"><?php _e('Download File', 'author'); ?></a></button>
                 </li>
                 <?php endif; 
    echo '<br />'.$link;
    exit;
    ?>
    
    PHP:
    Then you can see what the link is. If it's not http://www.linkineed.com follow get_post_meta(get_the_ID(), 'portfolio_link', TRUE); back to see where it's being set to what you don't want.
     
    Rukbat, Dec 10, 2011 IP
  8. Jaxo

    Jaxo Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #8
    You'll probably need basename(), or some fancy Regex. It all depends on what you have.

    Also, I believe Rukbat's code could be changed from if($link != '') to if($link) and echo '<br />'.$link;exit; to exit('<br />'.$link);
     
    Jaxo, Dec 14, 2011 IP