Ugrás a tartalomhoz


Összetett/ részletes keresés

összeteett részletes keresés search

8 válasz erre a témára

#1 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-03 - 16:02

Sziasztok!

Azzal a kérdéssel fordulok hozzátok, hogy szeretnék egy részletes összetett keresőt az oldalamra. A következő adottságokkal gondoltam:

Név: szöveges mező
Ország: választható kategória (drop down)
Város: választható kategória (drop down)

Ennek eredményeként a kategóriában található cikkeket kellene kilistáznia.

Több plugint is próbáltam:
Multiple Category Selection Widget

Ajax Categories Posts Dropdown

Ajaxy Live Search

Search By Category

Ezeken kívül a Super search nevű plugin, ami értelmes, viszont abban csak az országokat tudom kilistázni. Próbáltam a plugin forráskódjába belenyúlni, létrehozni egy category2-t, amiben a sima category tartalmát listázná, ahol az Országok alá a Városok kategória van rendelve, de nem sikerült.

Tudnátok ajánlani valamit? Köszönöm előre is! Örök hálám!

#2 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-04 - 15:32

van egy ilyen alapom, tehát eszerint festene a dolog:
<div id="content_right">	 
		    <ul>
		    <ul>
<form method="post" action="szallasok">
<table border=0>
<tr>
<td>Név</td>
<td><input type=text name="nev" value="" /></td>
</tr>
<tr>
<td>Ország</td><td><select name=country ONCHANGE="location = location + '&country='+this.options[this.selectedIndex].value;">
<option value="">Minden</option>
<option value="1">Magyarország</option><option value="2">Ausztria</option></select></td></tr>
<tr>
<td>Város</td><td><select name=city>
<option value="">Minden</option>
<option value="1">Budapest</option><option value="9">Böckstein</option><option value="5">Eger</option><option value="7">Jenig</option><option value="11">Mátramindszent</option><option value="10">Nemesnép</option><option value="3">Révfülöp</option><option value="2">Székesfehérvár</option><option value="8">Turracher Höhe</option><option value="4">Visegrád</option></select></td></tr>
<tr><td colspan="2" align="right"><input type="submit" value="Keresés"/></td></tr>
</form>

</table>
    </ul>
		    </ul>
		
		
	    </div>

Viszont itt nekem az kellene, hogy az országokat és a városokat a kategóriákból olvassa ki, és aszerint listázza a keresési eredményt.

#3 Priest

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 16 Hozzászólás:

Elküldve: 2012-02-05 - 22:57

A Wp Custom Field Search plugin próbáltad már?
Én ezt használom.

#4 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-06 - 13:50

Ez tökéletes! :) Annyit tudsz esetleg még segíteni, hogy azt hogy tudom megcsinálni, hogy ha category labelt választok, akkor ne az összes kategóriát listázza, hanem csak adottakat? van olyan hogy: Drop Down Options, Compare...stb valahol van rá mód? köszi még egyszer!

#5 Priest

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 16 Hozzászólás:

Elküldve: 2012-02-06 - 14:39

A Drop Down Options-ban meg tudod adni, hogy mi jelenjen meg. Az adott kategórianeveket írd be vesszővel elválasztva.

#6 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-06 - 15:06

Megtaláltam. :) Az kivitelezhető, hogy mondjuk ha kiválasztanak az első drop downban egy kategóriát, akkor az alatta lévő drop downban csak a kiválasztott kategóriához tartozó alkategóriákat listázza?

#7 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-06 - 15:57

Ezt a kódrészletet találtam:

class CategorySearch {
}
class CustomSearchField extends SearchFieldBase {
function CustomSearchField($nameOrParams,$input=false,$comparison=false,$joiner=false){
  CustomSearchField::__construct($nameOrParams,$input,$comparison,$joiner);
}
function __construct($nameOrParams,$input=false,$comparison=false,$joiner=false){
  parent::__construct();
  if(!is_array($nameOrParams)){
   $params = array('name'=>$nameOrParams);
  } else {
   $params = $nameOrParams;
  }
  $this->name = $params['name'];
  $this->params = $params;
  $this->joiner = $joiner;
  $this->comparison = $comparison;
  $this->input = $input;
  if(!is_object($this->input)){
   $input = $this->param('input','TextField');
   $this->input = new $input($params);
  }
  if(!is_object($this->comparison)){
   $comparison = $this->param('comparison','LikeComparison');
   $this->comparison = new $comparison();
  }
  if(!is_object($this->joiner)){
   $joiner = $this->param('joiner','CustomFieldJoiner');
   $this->joiner = new $joiner($this->param('name'),$this->params);
  }

}
function setIndex($n){
  $this->index=$n;
}
function param($key,$default=null){
  if(array_key_exists($key,$this->params)) return $this->params[$key];
  return $default;
}
function stripInitialForm($form){
  $pref='<!--cs-form-->';
  if(preg_match("/^$pref/",$form)) return $form;
  else return $pref;
}
function form_inputs($form){
  $form = $this->stripInitialForm($form);
  return $form.$this->getInput($this->name,$this->joiner);
}
function hasValue(){
  return $this->getValue();
}
function sql_restrict($where){
  if($this->hasValue()){
   $value = $this->getValue();
   $value = $GLOBALS['wpdb']->escape($value);
   $where.=$this->joiner->sql_restrict($this->name,$this->index,$value,$this->comparison);
  }
  if(method_exists($this->joiner,'process_where'))
   $where = $this->joiner->process_where($where);
  return $where;
}
function describeSearch($current){
  if($this->hasValue()){
   $current[] = $this->getLabel()." ".$this->comparison->describeSearch($this->getValue());
  }
  return $current;
}
function join_meta($join){
  global $wpdb;
  $join=$this->joiner->sql_join($join,$this->name,$this->index,$this->getValue(),$this->comparison);
  return $join;
}
function getQualifiedName(){
  return $this->name.'-'.$this->index;
}
function getOldValue(){ return $this->getValue(); }
function getValue(){
  $v = $this->input->getValue($this->getQualifiedName(),$this->name);
  return $v;
}
function getLabel(){
  if(!$this->params['label']) $this->params['label'] = ucwords($this->name);
  return $this->params['label'];
}
function isHidden(){
  return $this->input->param('hidden',false);
}
function getInput($wrap=true){
  $input = $this->input->getInput($this->getQualifiedName(),$this->joiner,$this->name);
  if($wrap){
   $input = "<div class='searchform-param'><label class='searchform-label'>".$this->getLabel()."</label><span class='searchform-input-wrapper'>$input</span></div>";
  }
  return $input;
}
function getCSSClass(){
  return method_exists($this->input,'getCSSClass')?$this->input->getCSSClass():get_class($this->input);
}
}
function wp_custom_search_fields_include_bridges(){
$dir = opendir($path = dirname(__FILE__).'/bridges');
while($file = readdir($dir)){
  if(is_file("$path/$file") && preg_match("/^[^.].*\.php$/",$file)){
   require_once("$path/$file");
  }
}
}
wp_custom_search_fields_include_bridges();
if($debugMode){
add_filter('posts_request','debug_dump_query');
function debug_dump_query($query){
  echo "<h1>$query</h1>";
  return $query;
}
}
?>


#8 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-06 - 16:04

Van ebben olyan rész, amit ha módosítunk, akkor lehetséges, hogy az adott kategória alkategóriáit listázza?

#9 Zolikens

    Új Tag

  • Regisztrált tag
  • PipaPipa
  • 68 Hozzászólás:
  • Település:Szeged

Elküldve: 2012-02-09 - 16:01

Nos, meg van végre pontosan a kategóriákra vonatkozó joiner és a keresés rész is az extra_search_fields. php fájlban.

joiner:
class CategoryJoiner extends BaseJoiner {
function sql_restrict($name,$index,$value,$comparison){
  if(!($value || $this->params['required'])) return $join;
  $table = 'meta'.$index;
  return " AND ( ".$comparison->addSQLWhere("$table.name",$value).")";
}
function getTaxonomy(){
  return $this->param('taxonomy','category');
}
function getTaxonomyWhere($table){
  return "`$table`.taxonomy='".$this->getTaxonomy()."'";
}
function sql_join($join,$name,$index,$value){
  if(!($value || $this->params['required'])) return $join;
  global $wpdb;
  $table = 'meta'.$index;
  $rel = 'rel'.$index;
  $tax = 'tax'.$index;
  return $join." JOIN $wpdb->term_relationships $rel ON $rel.object_id=$wpdb->posts.id JOIN  $wpdb->term_taxonomy $tax ON $tax.term_taxonomy_id=$rel.term_taxonomy_id JOIN $wpdb->terms $table ON $table.term_id=$tax.term_id AND ".$this->getTaxonomyWhere($tax);
}
function getAllOptions($fieldName){
  global $wpdb;
  $sql = "SELECT distinct t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id JOIN $wpdb->posts p ON tr.object_id=p.id AND p.post_status='publish' WHERE ".$this->getTaxonomyWhere('tt');
  $q = mysql_query($sql);
  if($e = mysql_error()) echo "<h1>SQL: $sql</h1>".mysql_error();
  $options = array();
  while($r = mysql_fetch_row($q))
   $options[$r[0]] = $r[0];
  return $options;
}
function needsField(){
  return false;
}
}
class TagJoiner extends CategoryJoiner {
function getTaxonomy(){
  return $this->param('taxonomy','post_tag');
}
}

search:
class CategorySearch {
}
class CustomSearchField extends SearchFieldBase {
function CustomSearchField($nameOrParams,$input=false,$comparison=false,$joiner=false){
  CustomSearchField::__construct($nameOrParams,$input,$comparison,$joiner);
}
function __construct($nameOrParams,$input=false,$comparison=false,$joiner=false){
  parent::__construct();
  if(!is_array($nameOrParams)){
   $params = array('name'=>$nameOrParams);
  } else {
   $params = $nameOrParams;
  }
  $this->name = $params['name'];
  $this->params = $params;
  $this->joiner = $joiner;
  $this->comparison = $comparison;
  $this->input = $input;
  if(!is_object($this->input)){
   $input = $this->param('input','TextField');
   $this->input = new $input($params);
  }
  if(!is_object($this->comparison)){
   $comparison = $this->param('comparison','LikeComparison');
   $this->comparison = new $comparison();
  }
  if(!is_object($this->joiner)){
   $joiner = $this->param('joiner','CustomFieldJoiner');
   $this->joiner = new $joiner($this->param('name'),$this->params);
  }

}
function setIndex($n){
  $this->index=$n;
}
function param($key,$default=null){
  if(array_key_exists($key,$this->params)) return $this->params[$key];
  return $default;
}
function stripInitialForm($form){
  $pref='<!--cs-form-->';
  if(preg_match("/^$pref/",$form)) return $form;
  else return $pref;
}
function form_inputs($form){
  $form = $this->stripInitialForm($form);
  return $form.$this->getInput($this->name,$this->joiner);
}
function hasValue(){
  return $this->getValue();
}
function sql_restrict($where){
  if($this->hasValue()){
   $value = $this->getValue();
   $value = $GLOBALS['wpdb']->escape($value);
   $where.=$this->joiner->sql_restrict($this->name,$this->index,$value,$this->comparison);
  }
  if(method_exists($this->joiner,'process_where'))
   $where = $this->joiner->process_where($where);
  return $where;
}
function describeSearch($current){
  if($this->hasValue()){
   $current[] = $this->getLabel()." ".$this->comparison->describeSearch($this->getValue());
  }
  return $current;
}
function join_meta($join){
  global $wpdb;
  $join=$this->joiner->sql_join($join,$this->name,$this->index,$this->getValue(),$this->comparison);
  return $join;
}
function getQualifiedName(){
  return $this->name.'-'.$this->index;
}
function getOldValue(){ return $this->getValue(); }
function getValue(){
  $v = $this->input->getValue($this->getQualifiedName(),$this->name);
  return $v;
}
function getLabel(){
  if(!$this->params['label']) $this->params['label'] = ucwords($this->name);
  return $this->params['label'];
}
function isHidden(){
  return $this->input->param('hidden',false);
}
function getInput($wrap=true){
  $input = $this->input->getInput($this->getQualifiedName(),$this->joiner,$this->name);
  if($wrap){
   $input = "<div class='searchform-param'><label class='searchform-label'>".$this->getLabel()."</label><span class='searchform-input-wrapper'>$input</span></div>";
  }
  return $input;
}
function getCSSClass(){
  return method_exists($this->input,'getCSSClass')?$this->input->getCSSClass():get_class($this->input);
}
}
function wp_custom_search_fields_include_bridges(){
$dir = opendir($path = dirname(__FILE__).'/bridges');
while($file = readdir($dir)){
  if(is_file("$path/$file") && preg_match("/^[^.].*\.php$/",$file)){
   require_once("$path/$file");
  }
}
}
wp_custom_search_fields_include_bridges();
if($debugMode){
add_filter('posts_request','debug_dump_query');
function debug_dump_query($query){
  echo "<h1>$query</h1>";
  return $query;
}
}
?>

Én úgy gondolom, hogy a search részbe kellene egy szűrés, csak azt nem tudom, hogy mire szűrjek rá, mert valószínűleg csak 1 kategória változó van megadva. ha úgy kellene megoldjam, hogy veszek fel 2. változót is, azt hogyan tehetem meg?





1 felhasználó olvassa ezt a témát.

0 felhasználó, 1 vendég, 0 anonim felhasználó