douzhan8652
2015-06-29 16:43
浏览 306
已采纳

高级自定义字段 - 添加Linkedin

I am having trouble creating a clickable Linkedin link in WordPress via Advanced Custom Fields Plugin. It was simple when I wanted to add phone number and email. But I can not figure out how to make just a Linkedin icon appear for each user as a clickable link.

Code: function member_contact() {

$vcard = get_field('vcard');
$bio   = get_field('bio_pdf');
$linkedin = get_field('linkedin');
$phone = get_field('phone');
$fax   = get_field('fax');
$email = get_field('email');

$post_info = '';

if (isset($vcard['url'])) {
    $img = get_stylesheet_directory_uri() . "/images/mail-icon.png";
    $post_info .= '<a class="vcard" href="'.$vcard['url'].'"><img src="'.$img.'" /> Download Contact</a>';
}

if (isset($bio['url']) && isset($vcard['url'])) {
    $post_info .= ' | ';
}

if (isset($bio['url'])) {
    $post_info .= '<a class="bio-pdf" href="'.$bio['url'].'">Download Bio</a>';
}

if (isset($linkedin['url']) && isset($vcard['url']) || isset($bio['url'])) {
    $post_info .= ' | ';
}

if (isset($linkedin['url'])) {
    $post_info .= '<a href="'.$linkedin['url'].'"><i class="fa fa-linkedin" style="color:blue"></i> Linkedin</a>';
}


$post_info .= '<ul class="member-contact">';
$post_info .= "<li>$email</li>";
$post_info .= "<li>p: $phone</li>";
$post_info .= "<li>f: $fax</li>";
$post_info .= "</ul>";
var_dump($linkedin);

Code from a user's repo (Kevinlearynet),which I am not sure how to integrate

                <?php if ( $linkedin = get_field('team_linkedin') ): ?>
                <a href="<?php echo $linkedin; ?>"><i class="icon-linkedin"></i></a>
                <?php endif; ?>

Dump for $linkedin

string(21) "https://www.yahoo.com"

Pictures: enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutui7955 2015-06-29 16:59
    已采纳

    You can edit your code like this to integrate the linkedin link.

    function member_contact() {
    
            $vcard = get_field('vcard');
            $bio   = get_field('bio_pdf');
            $phone = get_field('phone');
            $fax   = get_field('fax');
            $linkedin = get_field('linkedin');
            $email = get_field('email');
    
            $post_info = '';
    
            if (isset($vcard['url'])) {
                $img = get_stylesheet_directory_uri() . "/images/mail-icon.png";
                $post_info .= '<a class="vcard" href="'.$vcard['url'].'"><img src="'.$img.'" /> Download Contact</a>';
            }
    
            if (isset($bio['url']) && isset($vcard['url'])) {
                $post_info .= ' | ';
            }
    
            if (isset($bio['url'])) {
                $post_info .= '<a class="bio-pdf" href="'.$bio['url'].'">Download Bio</a>';
            }
    
            $post_info .= '<ul class="member-contact">';
            $post_info .= "<li>$email</li>";
            $post_info .= "<li>p: $phone</li>";
            $post_info .= '<a href="$linkedin"><i class="icon-linkedin"></i></a>';
            $post_info .= "<li>f: $fax</li>";
            $post_info .= "</ul>";
    
            genesis_markup( array(
                'html5' => sprintf( '<div class="entry-meta">%s</div>', $post_info ),
                'xhtml' => sprintf( '<div class="post-info">%s</div>', $post_info ),
            ) );
    
        }
    
    点赞 评论
  • doson1998 2015-06-29 16:59

    You are already assigning the LinkedIn field to a variable, so you just need to construct the link now:

    function member_contact() {

    $vcard = get_field('vcard');
    $bio   = get_field('bio_pdf');
    $phone = get_field('phone');
    $fax   = get_field('fax');
    $linkedin = get_field('linkedin');
    $email = get_field('email');
    
    $post_info = '';
    
    if (isset($vcard['url'])) {
        $img = get_stylesheet_directory_uri() . "/images/mail-icon.png";
        $post_info .= '<a class="vcard" href="'.$vcard['url'].'"><img src="'.$img.'" /> Download Contact</a>';
    }
    
    if (isset($bio['url']) && isset($vcard['url'])) {
        $post_info .= ' | ';
    }
    
    if (isset($bio['url'])) {
        $post_info .= '<a class="bio-pdf" href="'.$bio['url'].'">Download Bio</a>';
    }
    
    $post_info .= '<ul class="member-contact">';
    $post_info .= "<li>$email</li>";
    $post_info .= "<li>p: $phone</li>";
    $post_info .= "<li>f: $fax</li>";
    //NEW LINE ADDED BELOW
    $post_info .= "<li><a href="'.$linkedin.'" class="linkedInButton"></a></li>";
    //NEW LINE ADDED ABOVE
    $post_info .= "</ul>";
    
    genesis_markup( array(
        'html5' => sprintf( '<div class="entry-meta">%s</div>', $post_info ),
        'xhtml' => sprintf( '<div class="post-info">%s</div>', $post_info ),
    ) );
    

    }

    This will output your LinkedIn link immediately after the Fax Number in this function.

    Then you would just need to style your tag with the class "linkedInButton" to have a LinkedIn icon as a background image, set the height and width of the icon, change its display to block or inline-block (as needed), and you'll be all set.

    As an FYI, Advanced Custom Fields has a URL field which I'd recommend using instead of a text field. Doing this incorporates some validation to ensure that a valid URL is used.

    点赞 评论

相关推荐 更多相似问题