当 ACF 字段之一为空时隐藏前端中的 ACF 字段
我目前正在尝试在前端显示字段,但它们是文件/上传。所以它们并不总是被使用。我正在尝试弄清楚在没有上传时如何隐藏字段。在研究了一些内容后,我目前有了这段代码,但它不起作用。抱歉,我目前仍在学习 PHP。
任何帮助将不胜感激。
function woo_new_tab_content() {
// The new tab content
if (get_field ('tech_sheet'));
echo '<h3><a href="'. get_field('tech_sheet') .'" target="_blank">Download Tech Sheet</a></h3>';
if (get_field ('datasheet'));
echo '<h3><a href="'. get_field('datasheet') .'" target="_blank">Download Datasheet</a></h3>';
if (get_field ('datasheet_2'));
echo '<h3><a href="'. get_field('datasheet_2') .'" target="_blank">Download Datasheet</a></h3>';
if (get_field ('datasheet_3'));
echo '<h3><a href="'. get_field('datasheet_3') .'" target="_blank">Download Datasheet</a></h3>';
}
I am currently trying to show fields in the front-end, however they're files/uploads. So they're not always used. I am trying to work out how you hide fields when there is no upload. I currently have this code after researching some bits, but it isn't working. I do apologise, I am currently still learning PHP.
Any help would be greatly appreciated.
function woo_new_tab_content() {
// The new tab content
if (get_field ('tech_sheet'));
echo '<h3><a href="'. get_field('tech_sheet') .'" target="_blank">Download Tech Sheet</a></h3>';
if (get_field ('datasheet'));
echo '<h3><a href="'. get_field('datasheet') .'" target="_blank">Download Datasheet</a></h3>';
if (get_field ('datasheet_2'));
echo '<h3><a href="'. get_field('datasheet_2') .'" target="_blank">Download Datasheet</a></h3>';
if (get_field ('datasheet_3'));
echo '<h3><a href="'. get_field('datasheet_3') .'" target="_blank">Download Datasheet</a></h3>';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试这个:
Please try this: