首页 > 解决方案 > 选定的过滤器应显示在活动过滤器列表中

问题描述

我有一个展示一些产品的网站。像许多其他网站一样,我正在尝试过滤结果。我有一个彩色滤光片。我正在显示颜色缩略图,并在选择任何颜色缩略图时,页面将重定向并加载具有该颜色的产品。现在我有一个额外的<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>

任何帮助表示赞赏。

标签: phphtml

解决方案


只需执行另一个循环并打印缩略图(如果它们被选中)。

<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>

推荐阅读