-2
我想在wordpress的header.php模板中使用此代碼來使用ACF插件字段。 但它不起作用。如href
屬性不起作用。如何在echo函數中使用字符串變量
這是我的代碼:
echo '<div align="center">';
//Rule Adress
if (the_field("rule") != 'http://' || the_field("rule") != '') {
echo '<a href="' . the_field('rule') . '" role="button" class="Button Button--error" title="Rules" rel="nofollow" target="_blank"><i class="fa fa-fw fa-check"></i>Rules</a>';
}
//Cost
if (the_field("cost") != '0' || the_field("rule") != '') {
echo '<a role="button" class="Button Button--info" style="cursor: default;"><i class="fa fa-fw fa-shopping-cart"></i>Cost: ' . the_field('cost') . ' Dolor</a>';
}
//Demo
if (the_field("demo") != 'http://' || the_field("demo") != '') {
echo '<a href="' . the_field('demo') . '" role="button" class="Button Button--primary" title="Demo" rel="nofollow" target="_blank"><i class="fa fa-fw fa-heart"></i>Demo</a>';
} else {
echo '<a role="button" class="Button Button--primary" title="Demo" style="cursor: default;"><i class="fa fa-fw fa-heart"></i>Demo</a>';
}
//Shots
if (the_field("shots") != 'http://' || the_field("shots") != '') {
echo '<a href="' . the_field('shots') . '" role="button" class="Button Button--warning" title="Shots" rel="nofollow" target="_blank"><i class="fa fa-fw fa-desktop"></i>Shots</a>';
} else {
echo '<a role="button" class="Button Button--warning" title="Shots" style="cursor: default;"><i class="fa fa-fw fa-desktop"></i>Shots</a>';
}
echo '</div">';
字段is-product
,rule
,cost
,demo
和shot
是我的領域是在可溼性粉劑管理員定義的。
請幫我解決這個問題。
感謝@asherstoppard。我不能在'if'語句中使用the_field()嗎?這段代碼是否工作沒有任何錯誤? – 2015-03-02 16:00:24
完全沒問題,修正後爲你做了什麼? – asherstoppard 2015-03-09 09:41:04