【发布时间】:2011-11-14 16:25:41
【问题描述】:
我在搜索表达式引擎时遇到了一点问题!我有一个很好的下拉表单设置,但是我需要在这个搜索表单中添加一个可选的关键字字段。任何想法我将如何使用我当前的代码做到这一点:
主窗体代码:
<form method="post" action="/properties/search-results/">
<p>Keywords:</p>
<input id="keywords" type="text" name="keywords"/>
<p>Town:</p>
<select id="town" name="cat[]" multiple="multiple">
<option value="" selected="selected">Any</option>
{exp:channel:categories channel="property" style="linear" category_group="1"}
<option value="{category_id}">{category_name}</option>
{/exp:channel:categories}
</select>
<p>Property Type:</p>
<select id="propertyType" name="cat[]">
<option value="" selected="selected">Any</option>
{exp:channel:categories channel="property" style="linear" category_group="2"}
<option value="{category_id}">{category_name}</option>
{/exp:channel:categories}
</select>
<input style="margin-top:20px; width: 100px;" type="submit" name="submit" value="Search"/>
</form>
搜索结果模板:
<?php
// Grab the categories selected from the $_POST
// join them with an ampersand - we are searching for AND matches
$cats = "";
foreach($_POST['cat'] as $cat){
// check we are working with a number
if(is_numeric($cat)){
$cats .= $cat."&";
}
}
// strip the last & off the category string
$cats = substr($cats,0,-1);
?>
{exp:channel:entries channel="property" dynamic="on" category="<?php echo($cats);?>" orderby="date" sort="asc"}
我需要关键字字段来搜索我的条目的{title}!
感谢您的帮助!
【问题讨论】:
标签: php html search expressionengine