php - 选定的过滤器应显示在活动过滤器列表中
问题描述
我有一个展示一些产品的网站。像许多其他网站一样,我正在尝试过滤结果。我有一个彩色滤光片。我正在显示颜色缩略图,并在选择任何颜色缩略图时,页面将重定向并加载具有该颜色的产品。现在我有一个额外的<div>
地方,我显示活动颜色的缩略图。因此,一旦用户选择了颜色缩略图,它应该重新加载带有颜色过滤产品的页面,并且所选缩略图应该在活动过滤器中可见div
。我怎样才能做到这一点?
以下是我的代码:
<?
$uri = $this->web->uri;
if (!strrpos($this->web->uri, '?')){
$uri .= '?';
} else {
$uri .= '&';
}
?>
<div class='filter'>
<p class='filter_title'>Colors</p>
<div class='colors'>
<? foreach ($model->allColors as $color) { ?>
<a href="<?=$uri.'color='.$color->id?>" class='color' style="background-image:url(<?=$color->getThumbnail();?>)" >
</a>
<? } ?>
</div>
<div class='active_colors'>
<p class='filter_p'>Active colors</p>
<div class='act_color'>
//Here where I want the selected color thumbnail.
</div>
</div>
</div>
任何帮助表示赞赏。
解决方案
只需执行另一个循环并打印缩略图(如果它们被选中)。
<div class='filter'>
<p class='filter_title'>Colors</p>
<div class='colors'>
<? foreach ($model->allColors as $color) { ?>
<a href="<?= $uri.'color'.$color->id.'=1' ?>" class='color' style="background-image:url(<?= $color->getThumbnail(); ?>)" >
</a>
<? } ?>
</div>
<div class='active_colors'>
<p class='filter_p'>Active colors</p>
<div class='act_color'>
//Here where I want the selected color thumbnail.
<? foreach ($model->allColors as $color) : ?>
<? if(isset($_GET['color'.$color->id] ): ?>
<a href="<?= $uri ?>" class='color' style="background-image:url(<?= $color->getThumbnail(); ?>)" ></a>
<? endif; ?>
<? endforeach; ?>
</div>
</div>
</div>
推荐阅读
- python - 如何在同一个 for 语句中迭代多个不同的值?
- python - 无效的命令名称“!canvas”我该如何解决?
- python - SqlAlchemy + SQL Server
- c++ - 为什么 std::make_error_code(std::errc) 存在?
- css - 当 Outlook 将垂直白线添加到表格单元格中的 img 时,是否有一致的修复?
- javascript - 为什么“this”关键字在用作回调时指代调用函数的人,而在其他情况下指代对象所有者?
- docker - 在 Dockerfile 中检测用户名
- python - django formset模板循环遍历字段禁用删除功能
- javascript - AJAX 请求不发送 cookie (NET 5)
- onclick - thymeleaf onclick 参数