【发布时间】:2017-12-17 11:16:03
【问题描述】:
早上好。 我已经设置了一个自定义字段修改 function.php 的列表。一切正常,但我想在字段为空时隐藏。我已经阅读了很多关于它的帖子,但我无法摆脱我的问题。
这里是我的 php 代码:
// Show advanced custom fields in product detail page
add_action( 'woocommerce_single_product_summary', "ACF_product_content", 26 );
function ACF_product_content(){
if (function_exists('the_field')){
echo '<b>MATERIA: </b>';
the_field('materia');
echo "<br />";
echo '<b>FECHA DE EDICIÓN: </b>';
the_field('fecha_de_edicion');
echo "<br />";
echo '<b>LUGAR DE EDICIÓN: </b>';
the_field('lugar_de_edicion');
echo "<br />";
echo '<b>ISBN: </b>';
the_field('isbn');
echo "<br />";
echo '<b>ISBN DIGITAL: </b>';
the_field('isbn_digital');
echo "<br />";
echo '<b>ENCUADERNACIÓN: </b>';
the_field('encuadernacion');
echo "<br />";
echo '<b>INTERIOR: </b>';
the_field('interior');
echo "<br />";
echo '<b>MEDIDAS: </b>';
the_field('medidas');
echo "<br />";
echo '<b>NÚMERO DE PÁGINAS: </b>';
the_field('numero_de_paginas');
echo "<br />";
echo '<b>IDIOMA: </b>';
the_field('idioma');
echo "<br />";
echo '<b>CÓDIGOS IBIC: </b>';
the_field('ibic');
}
}
如果其中一个字段为空,谁能帮我隐藏它? 谢谢
【问题讨论】:
-
使用
if检查该字段是否为空,如果if为假,则通过不打印来隐藏它。你可以用一个 for 循环和一个数组或其他东西来做这件事,但基本的 if 是一个开始。
标签: php wordpress field custom-fields