If exists display php link?

Discussion in 'PHP' started by Audiomad, Apr 4, 2012.

  1. #1
    I'm trying to get specific links to show if the form feilds have been filled in, this is a part of wordpress using a function to get social network links to display only problem is they show even if they are empty, the form if not linked gives a link back to the page its self.

    <a title="Twitter" class="grey" href="<?php echo the_author_meta('twitter'); ?>">Twitter</a>,  
    <a title="Facebook" class="grey" href="<?php echo the_author_meta('facebook'); ?>">Facebook</a>, 
    <a title="Digg" class="grey" href="<?php echo the_author_meta('digg'); ?>">Digg</a>, 
    <a title="Flicker" class="grey" href="<?php echo the_author_meta('flicker'); ?>">Flicker</a>, 
    <a title="LinkedIn" class="grey" href="<?php echo the_author_meta('linkedIn'); ?>">LinkedIn</a>
    Code (markup):
    I'm not much of php coder so trying to over write the <?php echo the_author_meta('twitter'); ?> part is giving me errors and not working.
     
    Audiomad, Apr 4, 2012 IP
  2. Uploadables

    Uploadables Member

    Messages:
    100
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #2
    You can use
    [LEFT][COLOR=#000000][FONT=Consolas]if(isset($_POST['your 'name' value of the field']))[/FONT][/COLOR][/LEFT]
    Code (markup):
    That will determine if the field has been submitted.
     
    Uploadables, Apr 4, 2012 IP
  3. Artuurs

    Artuurs Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if(empty($_POST['postname']))
    {
    //code
    }
     
    Artuurs, Apr 7, 2012 IP
  4. Uploadables

    Uploadables Member

    Messages:
    100
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #4
    Would need to be :

    if(!empty($_POST['postname']))
    {
    //code
    }
    Code (markup):
     
    Uploadables, Apr 7, 2012 IP
  5. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #5
    If these are set via the admin panel:

    
    <?PHP if(the_author_meta('twitter') != "") { echo the_author_meta('twitter'); } <?>
    
    PHP:
    Otherwise the other solutions will work.
    The only issue is, this will not check to see if they are valid URL's
     
    Grit., Apr 7, 2012 IP
  6. www.seotest.com

    www.seotest.com Well-Known Member

    Messages:
    77
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    168
    #6
    <?PHP if(the_author_meta('twitter')) { echo the_author_meta('twitter'); } ?>

    same like yours but better
     
    www.seotest.com, Apr 7, 2012 IP
  7. Audiomad

    Audiomad Peon

    Messages:
    1,028
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I've tried that but when making it a link it still comes up with a link to the page "empty field"
     
    Audiomad, Apr 7, 2012 IP
  8. sitescripts

    sitescripts Active Member

    Messages:
    600
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    88
    Digital Goods:
    10
    #8
    can we see more code, like the_author_meta function?
     
    sitescripts, Apr 7, 2012 IP
  9. Audiomad

    Audiomad Peon

    Messages:
    1,028
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Here it is.

    <?php
    add_action('show_user_profile', 'wpsplash_extraProfileFields');
    add_action('edit_user_profile', 'wpsplash_extraProfileFields');
    add_action('personal_options_update', 'wpsplash_saveExtraProfileFields');
    add_action('edit_user_profile_update', 'wpsplash_saveExtraProfileFields');
    
    function wpsplash_saveExtraProfileFields($userID) {
    
    	if (!current_user_can('edit_user', $userID)) {
    		return false;
    	}
    
    	update_usermeta($userID, 'twitter', $_POST['twitter']);
    	update_usermeta($userID, 'facebook', $_POST['facebook']);
    	update_usermeta($userID, 'linkedin', $_POST['linkedin']);
    	update_usermeta($userID, 'digg', $_POST['digg']);
    	update_usermeta($userID, 'flickr', $_POST['flickr']);
    }
    
    function wpsplash_extraProfileFields($user)
    {
    ?>
    Code (markup):
     
    Audiomad, Apr 8, 2012 IP
  10. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #10
    <?PHP 
    if(the_author_meta('twitter') != "") { 
    echo the_author_meta('twitter');
     } else {
    echo "#";
    } <?>
    PHP:
    at least this way, it will not link out, it will look for an anchor
     
    Grit., Apr 8, 2012 IP