使用分类法来优化搜索结果

时间:2014-02-03 19:16:11

标签: php wordpress filter taxonomy

我是网络开发的新手,我的WordPress模板有点问题! 这是我正在谈论的页面:Click to see page

在此页面中,您只能看到特定位置的住宿(在本例中为Sevilla),我想要做的是以复选框的形式向侧边栏添加额外的过滤器,以便用户可以选择类型他们想要的某些设施的住宿。例如,如果用户检查侧边栏中的游泳池并单击提交,他们将只获得带有游泳池的住宿结果。

侧边栏默认使用模板,我知道去哪里,但我不知道如何添加这些额外的过滤器。 我正在考虑使用分类法作为过滤器,因为我们在创建一个新列表时从列表中检查住宿的设施!做这样的事情是可行的吗?

我希望我足够清楚并原谅我的英语 如果有人能给我任何指导或怎么做,我将不胜感激!谢谢

<?php
/**
 * The sidebar containing the main widget area.
 *
 * If no active widgets in sidebar, let's hide it completely.
 *
 * @package WordPress
 * @subpackage BookYourTravel
 * @since Book Your Travel 1.0
 */
?>
<?php if ( is_active_sidebar( 'sidebar' ) ) : ?>
    <aside id="secondary" class="widget-area  lower" role="complementary">
        <ul>
        <?php dynamic_sidebar( 'sidebar' ); ?>
        </ul>
    </aside><!-- #secondary -->
<?php endif; ?>

这是sidebar.php中出现的代码

也许这就是你想要的侧边栏代码:

<!--sidebar-->
    <aside class="left-sidebar">
        <article class="refine-search-results">
            <form id="side-search" method="get" action="<?php echo $custom_search_results_page; ?>">
                <h2><?php _e('Refine search results', 'bookyourtravel'); ?></h2>
                <dl>
                    <input name="what" id="what" value="<?php echo $what;?>" type="hidden" />
                    <!--Price (per night)-->
                    <?php 

                        $price_range_bottom = of_get_option('price_range_bottom', '0');
                        $price_range_increment = of_get_option('price_range_increment', '50');
                        $price_range_count = of_get_option('price_range_count', '5');
                        $default_currency = strtoupper(of_get_option('default_currency_select', 'USD'));

                        if ($price_range_count > 0) {
                    ?>
                    <?php if ($what == 1 || $what == 2) { ?>
                    <dt><?php _e('Price (per night)', 'bookyourtravel'); ?></dt>
                    <?php } elseif ($what == 3) { ?>
                    <dt><?php _e('Price (per day)', 'bookyourtravel'); ?></dt>
                    <?php } elseif ($what == 4) { ?>
                    <dt><?php _e('Price (per person)', 'bookyourtravel'); ?></dt>
                    <?php } ?>
                    <dd>
                        <?php 
                            $bottom = 0;
                            $top = 0;
                            $out = '';
                            for ($i=0; $i<$price_range_count;$i++) { 
                        ?>
                        <div class="checkbox">
                            <input type="checkbox" id="price<?php echo $i+1; ?>" name="price[]" value="<?php echo $i+1; ?>" />
                            <label for="price<?php echo $i+1; ?>">
                            <?php                               
                                $bottom = ($i * $price_range_increment) + $price_range_bottom;
                                $top = (($i+1) * $price_range_increment) + $price_range_bottom - 1;                             
                                $out = $bottom;
                                if ($i == ($price_range_count-1)) {
                                    $out.=  ' <span class="curr">' . $currency_symbol . '</span> +';
                                } else {
                                    $out.= " - " . $top . ' <span class="curr">' . $currency_symbol . '</span>';
                                }

                                echo $out;
                            ?>
                            </label>
                        </div>
                        <?php } ?>
                    </dd>
                    <!--//Price (per night)-->
                    <?php } ?>

                    <?php if ($what == 1 || $what == 2) { ?>
                    <dt><?php _e('Accommodation type', 'bookyourtravel'); ?></dt>
                    <dd>
                    <?php for ($i = 0; $i < count($accommodation_types); $i++) { 
                        $accommodation_type = $accommodation_types[$i];
                    ?>
                        <div class="checkbox">
                            <input value="<?php echo $accommodation_type->term_id; ?>" type="checkbox" id="ch<?php echo $i + 1; ?>" name="acc[]" />
                            <label for="ch<?php echo $i + 1; ?>"><?php echo $accommodation_type->name; ?></label>
                        </div>
                    <?php } ?>
                    </dd>
                    <!--//Accommodation type-->

                                                    <!--User rating-->
                    <dt><?php _e('User rating', 'bookyourtravel'); ?></dt>
                    <dd>
                        <div id="slider"></div>
                        <input type="hidden" id="rating" name="rating" value="" />
                        <span class="min">0</span><span class="max">10</span>
                    </dd>
                    <!--//User rating-->
                    <?php } elseif ($what == 3) { ?>
                    <dt><?php _e('Car type', 'bookyourtravel'); ?></dt>
                    <dd>
                    <?php for ($i = 0; $i < count($car_types); $i++) { 
                        $car_type = $car_types[$i];
                    ?>
                        <div class="checkbox">
                            <input value="<?php echo $car_type->term_id; ?>" type="checkbox" id="cth<?php echo $i + 1; ?>" name="car_types[]" />
                            <label for="cth<?php echo $i + 1; ?>"><?php echo $car_type->name; ?></label>
                        </div>
                    <?php } ?>
                    </dd>
                    <!--//Accommodation type-->
                    <?php } ?>
                </dl>

                <div class="f-item datepicker">
                    <span><?php _e('Date from', 'bookyourtravel'); ?></span>
                    <div class="datepicker-wrap"><input type="text" placeholder="" id="from" name="from" /></div>
                </div>
                <?php if ($what == 1 || $what == 2 || $what == 3) { ?>
                <div class="f-item datepicker">
                    <span><?php _e('Date to', 'bookyourtravel'); ?></span>
                    <div class="datepicker-wrap"><input type="text" placeholder="" id="to" name="to" /></div>
                </div>
                <?php } ?>
                <?php if ($what == 1 || $what == 2) { ?>
                <div id="destination" name="destination" class="f-item">
                    <span><?php _e('Your destination', 'bookyourtravel'); ?></span>
                    <input type="text" placeholder="<?php _e('City, region, district or specific accommodation', 'bookyourtravel'); ?>" id="term" name="term" />
                </div>
                <?php } elseif ($what == 3) { ?>
                <div id="destination" name="destination" class="f-item">
                    <span><?php _e('Pick Up', 'bookyourtravel'); ?></span>
                    <input type="text" placeholder="<?php _e('I want to pick up car in', 'bookyourtravel'); ?>" id="term" name="term" />
                </div>              
                <div id="destination2" name="destination2" class="f-item">
                    <span><?php _e('Drop Off', 'bookyourtravel'); ?></span>
                    <input type="text" placeholder="<?php _e('I want to drop off car at', 'bookyourtravel'); ?>" id="term_to" name="term_to" />
                </div>              
                <?php } elseif ($what == 4) { ?>
                <div id="destination" name="destination" class="f-item">
                    <span><?php _e('Tour location', 'bookyourtravel'); ?></span>
                    <input type="text" placeholder="<?php _e('City, region, district or specific tour', 'bookyourtravel'); ?>" id="term" name="term" />
                </div>
                <?php } ?>
                <input type="submit" value="<?php _e('Search again', 'bookyourtravel'); ?>" class="gradient-button" id="search-submit" />
            </form>
        </article>
    </aside>
    <!--//sidebar-->

1 个答案:

答案 0 :(得分:0)

从我看到的时候,我看到住宿下的页面是酒店和别墅。这两个似乎工作得很好。从我看到的我无法确定你的问题是什么。你可以稍微改写一下吗?