高级自定义字段 - 添加 Linkedin

Advanced Custom Fields - Adding Linkedin

我在通过 Advanced Custom Fields 插件在 WordPress 中创建可点击的 Linkedin link 时遇到问题。当我想添加 phone 号码和电子邮件时,这很简单。但我不知道如何让每个用户只显示一个 Linkedin 图标作为可点击的 link。

代码: 函数 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);

来自用户回购 (Kevinlearynet) 的代码,我不确定如何集成

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

转储 $linkedin

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

图片:

您已经将 LinkedIn 字段分配给一个变量,所以您现在只需要构建 link:

函数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 ),
) );

}

这将在此函数中的传真号码后立即输出您的 LinkedIn link。

那么您只需要使用 class "linkedInButton" 设置您的标签样式,将 LinkedIn 图标作为背景图片,设置图标的高度和宽度,将其显示更改为块状或内联块(根据需要),一切就绪。

仅供参考,高级自定义字段有一个 URL 字段,我建议使用它来代替文本字段。这样做包含一些验证以确保使用有效的 URL。

您可以像这样编辑代码以集成 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 ),
        ) );

    }