我创建了一个自定义帖子类型,其中包含自定义分类法和一个用于在清单中获取分类法术语的函数。在searchform中,我用手风琴调用这个函数。我的问题是当我喜欢在搜索表单中保留市场复选框时。主题是Avada的儿童主题。我怎么能这样做?
我的functions.php
/*===================================================
Show taxonomies in checklist
=====================================================*/
function get_terms_checklist($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$output ="<fieldset name='".$taxonomies."'><ul>";
foreach($myterms as $term){
$root_url = get_bloginfo('url');
$term_taxonomy=$term->taxonomy;
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$key=$taxonomies;
$output .="<li><input name='".$key."' type='checkbox' value='".$link."' />".$term_name."</li>";
}
return $output;
我的searchform.php
/*General Accordion****************************************************************************/
/*Set style of open slide*/
.accordion section:target { background:#FFF; padding:10px;}
.accordion section:target:hover { background:#FFF; }
.accordion section:target h3 {width:90%;}
.accordion section:target h3 a{ color:#333; padding:0;}
.accordion section:target p {display:block;}
.accordion section h3 a{padding:18px 20px;display:block; font-size:14px; font-weight:normal;color:#eee; text-decoration:none; }
/*set style of closed slide*/
.accordion section{ float:left;overflow:hidden; color:#333; cursor:pointer; background: #333; margin:3px; }
.accordion section:hover {background:#444;}
.accordion section p { display:none; }
.accordion section:after{position:relative;font-size:14px;color:#000;font-weight:bold;}
.accordion section:nth-child(1):after{content:'1';}
.accordion section:nth-child(2):after{content:'2';}
.accordion section:nth-child(3):after{content:'3';}
.accordion section:nth-child(4):after{content:'4';}
.accordion section:nth-child(5):after{content:'5';}
.accordion section:nth-child(6):after{content:'6';}
.accordion section:nth-child(7):after{content:'7';}
/*End General Accordion****************************************************************************/
/*Vertical Accordion *************************************************************************/
.vertical section{ width:100%; height:40px;
-webkit-transition:height 0.2s ease-out;
-moz-transition:height 0.2s ease-out;
-o-transition:height 0.2s ease-out;
-ms-transition:height 0.2s ease-out;
transition:height 0.2s ease-out;
}
/*Set height of the slide*/
.vertical :target{ height:600px; width:97%; }
.vertical section h3 { position:relative; left:0; top:-5px; }
/*Set position of the number on the slide*/
.vertical section:after{ top:-60px;left:810px;}
.vertical section:target:after{ left:-9999px;}
<div>
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<div class="search-table">
<div class="search-field">
<?php $search_text = __(" " ); ?>
<div class="search_field">
<input type="text" class="field" value="<?php echo $search_text; ?>" onblur="if (this.value == '') {this.value = '<?php echo $search_text; ?>';}" onfocus="if (this.value =='<?php echo get_search_query() ?>') {this.value = '<?php echo get_search_query() ?>';} {this.name = 's';}" />
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'ciutats';
$args =array('orderby'=>'name','hide_empty'=>true);
$ciutat_select=get_terms_checklist($taxonomies, $args);
?>
<section id="ciutat">
<h3><a href="#ciutat"> <strong>Escull la ciutat</strong></a></h3>
<p ><?php echo $ciutat_select; ?></p>
</section>
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'districtes';
$args = array('orderby'=>'name','hide_empty'=>true);
$districte_select = get_terms_checklist($taxonomies, $args); ?>
<section id="districtes">
<h3><a href="#districtes"><strong>Escull el districte</strong></a></h3>
<p><?php echo $districte_select; ?></p>
</section>
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'barris';
$args = array('orderby'=>'name','hide_empty'=>true);
$barri_select = get_terms_checklist($taxonomies, $args); ?>
<section id="barris">
<h3><a href="#barris"> <strong>Escull el barri</strong></a></h3>
<p><?php echo $barri_select; ?></p>
</section>
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'ambits';
$args = array('orderby'=>'name','hide_empty'=>true);
$ambit_select = get_terms_checklist($taxonomies, $args); ?>
<section id="ambits">
<h3><a href="#ambits"> <strong>Escull l'àmbit </strong></a></h3>
<p><?php echo $ambit_select;?></p>
</section>
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'colectius';
$args = array('orderby'=>'name','hide_empty'=>true);
$colectiu_select = get_terms_checklist($taxonomies, $args); ?> <section id="colectius">
<h3> <a href="#colectius"><strong>Escull el col.lectiu </strong></a></h3>
<p><?php echo $colectiu_select; ?></p>
</section>
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'serveis';
$args = array('orderby'=>'name','hide_empty'=>true);
$servei_select = get_terms_checklist($taxonomies, $args); ?>
<section id="serveis">
<h3><a href="#serveis"> <strong>Escull el servei </strong></a></h3>
<p><?php echo $servei_select; ?></p>
</section>
</div>
<div class="accordion vertical">
<?php
$taxonomies = 'especificitatserveis';
$args = array('orderby'=>'name','hide_empty'=>true);
$especificitatservei_select = get_terms_checklist($taxonomies, $args);
?>
<section id="especificitatservei">
<h3><a href="#especificitatservei"> <strong>Escull l'especificitat del servei </strong></a></h3>
<p><?php echo $especificitatservei_select; ?></p>
</section>
</div>
</div>
<div class="search-button">
<input type="submit" id="searchsubmit" value="" />
</div>
</form>
</div>
答案 0 :(得分:0)
由于您的表单方法是get
,因此所有这些选择都应该可以在$_GET
超全局或javascript(阅读this SO thread)中的php中使用。
答案 1 :(得分:0)
我的功能php:
/*===================================================
Show taxonomies en checklist
=====================================================*/
function get_terms_checklist($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$output ="<fieldset name='".$taxonomies."'><ul>";
foreach($myterms as $term){
$root_url = get_bloginfo('url');
$term_taxonomy=$term->taxonomy;
$term_slug=$term->slug;
$term_name =$term->name;
if ((isset($_GET[$taxonomies])) && ($term_slug==$_GET[$taxonomies]))
{$output .="<li><input name='".$taxonomies."' type='checkbox' value='".$term_slug."' checked/> ".$term_name."</li>"; }
else {$output .="<li><input name='".$taxonomies."' type='checkbox' value='".$term_slug."' /> ".$term_name."</li>";}
}
return $output;
}