我有以下代码:-
<ul class="grid effect-2" id="grid">
<?php
if( have_rows('gallery') ):
while ( have_rows('gallery') ) : the_row(); ?>
<?php
$image_location = get_sub_field('image_location');
if (empty($_GET['filter'])) {
$image_filter = $image_location == 'Nottingham' || $image_location == 'Corby';
} else {
$image_filter = $image_location == $_GET['filter'];
}
?>
<?php
if($image_filter) {
?>
<li><a class="fancybox" rel="gallery" href="<?php the_sub_field('image'); ?>" title="<?php echo $image_location . ' @ Planet Bounce ' . get_sub_field('image_location'); ?>"><img src="<?php the_sub_field('image'); ?>" alt="<?php echo get_sub_field('image_caption') . ' @ Planet Bounce ' . $image_location; ?>" /></a></li>
<?php } ?>
<?php endwhile;
else : endif;
?>
</ul>$image_location既可以是“诺丁汉”,也可以是“科尔比”,也可以两者兼而有之。图像过滤器基本上是对正在显示的图像进行过滤。
虽然上面的代码可以工作,但我认为这样做是不对的。
如果有人能帮助我更好地实践同样的查询方式,那将是非常感谢的。
如果你需要我更详细的解释,请告诉我。
发布于 2016-04-21 09:56:48
可以使用数组将条件包装在两个线性代码中。
$imageFilters = array('Nottingham'=>'Nottingham', 'Corby'=>'Corby');
$image_filter = isset($imageFilters[$_GET['filter']]) ? $imageFilters[$_GET['filter']] : $_GET['filter'];https://stackoverflow.com/questions/36765934
复制相似问题