请多多包涵。编程新手。
我正在尝试使用ACF和Repeater插件创建餐厅菜单。
下面的屏幕截图显示了我正在尝试实现的目标。这是已经将数据添加到数据库的后端。
这是我获取所需字段的基本循环。
<?php while( have_rows('menus') ): the_row(); ?>
<?php
$item_name = get_sub_field('item_name');
$item_price = get_sub_field('item_price');
$item_description = get_sub_field('item_description');
$special = get_sub_field('special');
?>
<h1 class="<?php echo $special"?>>
<?php echo $item_name ?>...<?php echo $item_price ?>
</h1>
<h2><?php echo $item_description ?></h2>
<?php endwhile; // end of the loop. ?>
我有三个模板,每个模板显示相同的菜单,但是在某些页面中,将显示“特殊”项目,其中将类设置为CSS样式。
例如
国王的十字页列出了菜1和菜2(特殊)
但
柯芬园页面列出了菜1,并跳过了菜2,因为它被选为国王十字的特殊菜。
如何跳过未分配给特定模板的字段?
谢谢你。
对,仍然不确定我是否完全理解这一点,但是如果我做对了,您是否需要检查页面是否等于特殊字段?
就像是:
<?php while( have_rows('menus') ) : the_row();
$item_name = get_sub_field('item_name');
$item_price = get_sub_field('item_price');
$item_description = get_sub_field('item_description');
$special = get_sub_field('special');
?>
<?php if( $special == get_the_title() ) :
?>
<h1 class="<?php echo $special; ?>">
<?php echo $item_name ?>...<?php echo $item_price ?>
</h1>
<h2><?php echo $item_description ?></h2>
<?php
endif;
endwhile; // end of the loop. ?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句