2011-11-14 4 views
0

표현 엔진 검색에 약간의 문제가 있습니다! 나는 위대한 작품 양식을 드롭 다운있어,하지만 난이 검색 양식에 OPTIONAL 키워드 필드를 추가해야합니다. 난 내 현재 코드와 함께이 작업을 수행 할 수 있습니다 모든 아이디어를 어떻게 :표현 엔진 고급 검색 - 키워드 검색 문제

기본 폼 코드 :

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

나는에서 검색하는 키워드 필드에 필요한 { 내 항목의 제목}!

도움 주셔서 감사합니다.

+0

은 아무도 이것을 알고 있나요 ??? – kala233

답변

1

다음을 시도해보십시오. 먼저 Search Fields 플러그인을 설치하십시오. (네이티브 EE "search:field_name" 매개 변수는 사용자 정의 필드가 아닌 항목 제목에 작동하기 때문에 당신이 필요합니다.)

는이 수정 된 코드를 사용

<?php 
// Grab the categories selected from the $_POST 
// join them with an ampersand - we are searching for AND matches 
$cats = array(); 
foreach($_POST['cat'] as $cat) 
{ 
    // check we are working with a number 
    if(is_numeric($cat)) 
    { 
     $cats[] = $cat; 
    } 
} 
$cats = implode('&', $cats); 

if(!empty($_POST['keywords'])) 
{ 
    $keywords = trim($_POST['keywords']); 
} 
?> 

<?php if($keywords) : ?> 
{exp:search_fields search:title="<?php echo($keywords);?>" channel="property" parse="inward"} 
<?php endif; ?> 
    {exp:channel:entries channel="property" <?php if($keywords) : ?>entry_id="{search_results}"<?php endif; ?> category="<?php echo($cats);?>" orderby="date" sort="asc"} 
     {!-- do stuff --} 
    {/exp:channel:entries} 
<?php if($keywords) : ?> 
{/exp:search_fields} 
<?php endif; ?> 
+0

안녕하세요 Derek, 고맙습니다. 그러나이 문제는 조금 문제가 있습니다. 어떤 오류나 아무것도보고하지 않지만 검색 양식을 제출하면 빈 페이지가 나타납니다. – kala233

+0

안녕하세요, Derek 님, PHP 구문 분석을 출력으로 변경했습니다. 이제 3 자 이상을 검색하더라도 "검색은 3 자 여야합니다."라는 표현 엔진 템플릿 페이지가 표시됩니다. – kala233

+0

PHP가 반드시 입력되어야합니다. index.php 파일에서 debug를 1로 설정하면 어떤 오류가 나올지 알 수 있습니다. –