Defult Download link if none added

Discussion in 'PHP' started by tomcromp, Mar 29, 2010.

  1. #1
    Hello in my wp admin i have a place to add download link which post an image and link to download site above videos here is the code:
    <?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){?>
    
                <a href="<?php echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true)?>" target="_blank"><div id="download"></div></a>
    PHP:
    How would i make it if i didnt add the link it would show a defult link?

    Cheers
    Tom
     
    tomcromp, Mar 29, 2010 IP
  2. tomcromp

    tomcromp Active Member

    Messages:
    454
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Does anyone know?
     
    tomcromp, Mar 30, 2010 IP
  3. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Insert an else block to the if structure where you output your default download link ;)
     
    Nyu, Mar 30, 2010 IP
  4. tomcromp

    tomcromp Active Member

    Messages:
    454
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I used:
    <?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){
    
    <a href="<?php echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true)?>" target="_blank"><div id="download"></div></a>
    
    else {
    echo "http :// defaultlink/download.html" target="_blank"><div id="download"></div></a>";
    }
    ?>
    
    PHP:
    But i get Parse error: syntax error, unexpected '<' in /home/.puffball/free****uk/e2tv.tv/wp-content/themes/MovieSitePress/single.php on line 77

    any help please
     
    tomcromp, Mar 30, 2010 IP
  5. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #5
    
    <a href="<?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){
    
    echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true);
    
    else {
    echo 'http :// defaultlink/download.html';
    }
    ?>
    " target="_blank"><div id="download"></div></a>
    
    PHP:
     
    Last edited: Mar 30, 2010
    stephan2307, Mar 30, 2010 IP
  6. nice.wallpapers

    nice.wallpapers Active Member

    Messages:
    142
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Hi plz try this code

    <?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){
    
    <a href="<?php echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true)?>" target="_blank"><div id="download"></div></a>
    
    else {
    echo 'http :// defaultlink/download.html" target="_blank"><div id="download"></div></a>';
    }
    ?>
    PHP:

     
    nice.wallpapers, Mar 30, 2010 IP
  7. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #7
    stephan2307, Mar 30, 2010 IP
  8. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This code should work:

    
    <?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){?>
                <a href="<?php echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true)?>" target="_blank"><div id="download"></div></a>
    <?php } else { ?>
                <a href="default_link.html" target="_blank"><div id="download"></div></a>
    <?php } ?>
    
    PHP:
    //edit: you did not post the ending if bracket in you original post so if there is more code that follows after that fir a href you new the take care of that
     
    Nyu, Mar 30, 2010 IP
  9. tomcromp

    tomcromp Active Member

    Messages:
    454
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Does not work get
    Parse error: syntax error, unexpected T_ELSE in /home/.puffball/freeshituk/e2tv.tv/wp-content/themes/MovieSitePress/single.php on line 81

    and that gets this error
    Parse error: syntax error, unexpected '<' in /home/.puffball/freeshituk/e2tv.tv/wp-content/themes/MovieSitePress/single.php on line 80
     
    tomcromp, Mar 30, 2010 IP
  10. tomcromp

    tomcromp Active Member

    Messages:
    454
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #10
    that gives Parse error: syntax error, unexpected '}' in /home/.puffball/freeshituk/e2tv.tv/wp-content/themes/MovieSitePress/single.php on line 86

    
     <?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){?>
    
                <a href="<?php echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true)?>" target="_blank"><div id="download"></div></a>
    PHP:
    is the code atm
     
    tomcromp, Mar 30, 2010 IP
  11. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #11
    sorry my fault. This should work now

    
    <a href="<?php if(get_post_meta(get_the_ID(), '_video_dvd_downurl',true)){
    
    echo get_post_meta(get_the_ID(), '_video_dvd_downurl',true);
    }
    else {
    echo 'http :// defaultlink/download.html';
    }
    ?>
    " target="_blank"><div id="download"></div></a>
    
    PHP:
     
    stephan2307, Mar 30, 2010 IP
  12. tomcromp

    tomcromp Active Member

    Messages:
    454
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #12
    Works thanks alot
     
    tomcromp, Mar 30, 2010 IP
  13. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #13
    No problem

    happy to help
     
    stephan2307, Mar 30, 2010 IP