Forums

[resolved] [closed] adding url (or <a href code) in an echo statement (2 posts)

  1. JaneLitte
    Member
    Posted 3 years ago #

    I need some coding help here. I want to capture a custom field and using an "if not null statement echo output in a link form". Here's what I thought would work but does not:

    <?php if ( $wpcm_number_facebook != '' ) { echo '<li><span class="number">'<a href=\"' . $wpcm_number_facebook. '\" /> (facebook) </a>' </li>'; } ?>

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    <?php
    // $fieldnm is null if the custom field doesn't exist
    $fieldnm = get_post_meta($post->ID,'yourfieldname',true);
    
    // If the field exists
    if($fieldnm) { ?> YOURHTMLHERE <?php } 
    
    // Field is null (doesn't exist)
    else { ?> SOMEOTHERHTML <?php }
    ?>

    Or using echo..

    <?php
    // $fieldnm is null if the custom field doesn't exist
    $fieldnm = get_post_meta($post->ID,'yourfieldname',true);
    
    // If the field exists
    if($fieldnm) { echo 'something to echo'; } 
    
    // Field is null (doesn't exist) // Remove if not needed
    else { echo 'the field is null'; }
    ?>

    Hope that helps...

    Update 'yourfieldname' with your actual custom field name.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.