douduandiao1368 2015-06-30 16:17
浏览 24
已采纳

PHP链接没有出现

I am trying to have the text "Facebook" to be a clickable link but for some reason it will not appear on the front-end.

Snippet of Code:

function friend_contact() {

$healthcard = get_field('healthcard');
$facebook = get_field('facebook');
$phone = get_field('phone');
$fax   = get_field('fax');
$email = get_field('email');

$post_info = '';

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

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

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


$post_info .= '<ul class="friend-contact">';
$post_info .= "<li>$email</li>";
$post_info .= "<li>p: $phone</li>";
$post_info .= "<li>f: $fax</li>";
$post_info .= "</ul>";

var_dump($facebook);    
var_dump(get_field('facebook'));

genesis_markup( array(
    'html5' => sprintf( '<div class="entry-meta">%s</div>', $post_info ),
    'xhtml' => sprintf( '<div class="post-info">%s</div>', $post_info ),
) );
}

Results of Dump:

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


enter image description here

Alternative Code With ['url']:

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

if (isset($facebook)) {
    $post_info .= '<a class="facebook" a href="$facebook"><i class="fa fa-facebook"></i> Facebook</a>';
    }

I think the root of the problem is with the code bit, ['url'] Thank you in advance

  • 写回答

2条回答 默认 最新

  • dpg76975 2015-06-30 18:49
    关注

    You echo your string with single quotes, thus it won't process the variable. That looks like it's between double quotes, but that is part of your string. So either make it

    $post_info .= '<a class="facebook" href="'.$facebook.'"><i class="fa fa-facebook"></i> Facebook</a>';
    

    or reverse the quotes.

    $post_info .= "<a class='facebook' href='$facebook'><i class='fa fa-facebook'></i> Facebook</a>";
    

    Edit: as to what's the better way, is another discussion. As long as you're consistent.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探