当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to display Categories as drop-down select in opencart?

问题描述:

I am trying to have two drop-down select for categories and sub categories. i am using the 3 level search logic from product/search.php and product/search.tpl. this template displays categories, subcategories, sub subcategories. But i want it to be like one drop-down select only all categories and other drop-down select only all sub categories( actually in my case subcategories will be same for all categories, only products will be different).

how can i achieve this?

i was successful in one drop-down select only categories, but not able to do it for sub categories

i want all this for a new search on header other than the normal search engine.

<div class="col-sm-3">

<select name="category_id" class="form-control">

<option value="0"><?php echo $text_category; ?></option>

<?php foreach ($categories as $category_1) { ?>

<?php if ($category_1['category_id'] == $category_id) { ?>

<option value="<?php echo $category_1['category_id']; ?>" selected="selected"><?php echo $category_1['name']; ?></option>

<?php } else { ?>

<option value="<?php echo $category_1['category_id']; ?>"><?php echo $category_1['name']; ?></option>

<?php } ?>

<?php } ?>

</select>

</div>

<div class="col-sm-3">

<select name="Subcategory_id" class="form-control">

<option value="0"><?php echo $text_subbcategory; ?></option>

<?php foreach ($categories as $category_1) { ?>

<?php foreach ($category_1['children'] as $category_2) { ?>

<?php if ($category_2['category_id'] == $category_id) { ?>

<option value="<?php echo $category_2['category_id']; ?>" selected="selected"><?php echo $category_2['name']; ?></option>

<?php } else { ?>

<option value="<?php echo $category_2['category_id']; ?>"><?php echo $category_2['name']; ?></option>

<?php } ?>

<?php } ?>

</select>

</div>

分享给朋友:
您可能感兴趣的文章:
随机阅读: