Skip to content

Instantly share code, notes, and snippets.

@gregoirenoyelle
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregoirenoyelle/812e6c84f6b32b96cefc to your computer and use it in GitHub Desktop.
Save gregoirenoyelle/812e6c84f6b32b96cefc to your computer and use it in GitHub Desktop.
wp-menu-recherche
<!-- Structure et fonction pour le menu de date -->
<li class="menu-item">
<select name="archive-dropdown" id="date">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array('format'=>'option', 'show_post_count'=>1) ); ?>
</select>
<script type="text/javascript">
var menuDate = document.getElementById("date");
function onCatChange() {
if ( menuDate.options[menuDate.selectedIndex].value != -1 ) {
location.href = menuDate.options[menuDate.selectedIndex].value;
}
}
menuDate.onchange = onCatChange;
</script>
</li>
<?php // NE PAS METTRE CETTE BALISE PHP
/**************************
* Ajout du menu de recherche
* après le menu principal.
* Seulement appliqué sur
* les archives category,
* tax, date.
*************************/
add_action('template_redirect','gn_affichage_menu' );
function gn_affichage_menu() {
if ( is_category() || is_tax() || is_date() ) {
add_action('genesis_after_header','gn_nav_search');
}
function gn_nav_search() { ?>
<nav class="nav-secondary" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<div class="wrap">
<ul class="menu genesis-nav-menu menu-secondary responsive-menu">
<li class="menu-item"></li>
</ul>
</div>
</nav>
<?php } // function gn_nav_search()
} // function gn_affichage_contenu_archive()
<nav class="nav-secondary">
<ul class="menu genesis-nav-menu menu-secondary responsive-menu" style="display: block;">
<li class="menu-item">
<select name="archive-dropdown" id="date">
<option value="">Choisir un mois</option>
<option value="http://monsite.fr/2015/05/"> mai 2015 &nbsp;(4)</option>
<option value="http://monsite.fr/2015/04/"> avril 2015 &nbsp;(17)</option>
<option value="http://monsite.fr/2015/03/"> mars 2015 &nbsp;(15)</option>
<option value="http://monsite.fr/2015/02/"> février 2015 &nbsp;(7)</option>
<option value="http://monsite.fr/2015/01/"> janvier 2015 &nbsp;(16)</option>
<option value="http://monsite.fr/2014/12/"> décembre 2014 &nbsp;(22)</option>
<option value="http://monsite.fr/2014/11/"> novembre 2014 &nbsp;(11)</option>
</select>
</li>
</ul>
</nav>
<?php // NE PAS METTRE CETTE BALISE PHP
/**************************
* Menu déroulant pour les taxonomie
* Affiche le menu déroulant
* en fonction des paramètres
**************************/
// use: gn_custom_taxonomy_dropdown( 'custom_taxo' )
function gn_custom_taxonomy_dropdown( $taxonomy, $id, $option, $exclude ='' ) {
$terms = get_terms( $taxonomy, array('exclude' => $exclude ) );
if ( $terms ) {
printf( '<select name="%s" class="postform" id="%s">', esc_attr( $taxonomy ), esc_attr( $id ) );
printf( '<option value"">%s</option>', esc_attr( $option ) );
foreach ( $terms as $term ) {
if ( $term->count < 2) continue;
printf( '<option value="%s">%s (%s)</option>', esc_attr( $term->slug ), esc_html( $term->name ), esc_html($term->count) );
}
print( '</select>' );
}
} // function gn_custom_taxonomy_dropdown()
/**************************
* Ajout du menu de recherche
* après le menu principal.
* Seulement appliqué sur
* les archives category,
* tax, date.
*************************/
add_action('template_redirect','gn_affichage_menu' );
function gn_affichage_menu() {
if ( is_category() || is_tax() || is_date() ) {
add_action('genesis_after_header','gn_nav_search');
}
function gn_nav_search() { ?>
<nav class="nav-secondary" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<div class="wrap">
<ul class="menu genesis-nav-menu menu-secondary responsive-menu">
<li class="menu-item">
<select name="archive-dropdown" id="date">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array('format'=>'option', 'show_post_count'=>1) ); ?>
</select>
<script type="text/javascript">
var menuDate = document.getElementById("date");
function onCatChange() {
if ( menuDate.options[menuDate.selectedIndex].value != -1 ) {
location.href = menuDate.options[menuDate.selectedIndex].value;
}
}
menuDate.onchange = onCatChange;
</script>
</li>
<li class="menu-item">
<?php gn_custom_taxonomy_dropdown( 'gntx_lieux', 'lieux', 'Choisir un lieu', '71'); ?>
<script type="text/javascript">
var menuLieu = document.getElementById("lieux");
function onCatChange() {
if ( menuLieu.options[menuLieu.selectedIndex].value != -1 ) {
location.href = "<?php echo home_url();?>/lieux/"+menuLieu.options[menuLieu.selectedIndex].value+"/";
}
}
menuLieu.onchange = onCatChange;
</script>
</li>
<li class="menu-item">
<?php gn_custom_taxonomy_dropdown( 'gntx_figure', 'figures', 'Choisir une personne', '32,67,81,90,80'); ?>
<script type="text/javascript">
var menuFigure = document.getElementById("figures");
function onCatChange() {
if ( menuFigure.options[menuFigure.selectedIndex].value != -1 ) {
location.href = "<?php echo home_url();?>/figures/"+menuFigure.options[menuFigure.selectedIndex].value+"/";
}
}
menuFigure.onchange = onCatChange;
</script>
</li>
</ul>
</div>
</nav>
<?php } // function gn_nav_search()
} // function gn_affichage_contenu_archive()
<nav class="nav-secondary" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<div class="wrap">
<ul class="menu genesis-nav-menu menu-secondary responsive-menu">
<li class="menu-item">
<select name="archive-dropdown" id="date">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array('format'=>'option', 'show_post_count'=>1) ); ?>
</select>
<script type="text/javascript">
var menuDate = document.getElementById("date");
function onCatChange() {
if ( menuDate.options[menuDate.selectedIndex].value != -1 ) {
location.href = menuDate.options[menuDate.selectedIndex].value;
}
}
menuDate.onchange = onCatChange;
</script>
</li>
<li class="menu-item">
<?php gn_custom_taxonomy_dropdown( 'gntx_lieux', 'lieux', 'Choisir un lieu', '71'); ?>
<script type="text/javascript">
var menuLieu = document.getElementById("lieux");
function onCatChange() {
if ( menuLieu.options[menuLieu.selectedIndex].value != -1 ) {
location.href = "<?php echo home_url();?>/lieux/"+menuLieu.options[menuLieu.selectedIndex].value+"/";
}
}
menuLieu.onchange = onCatChange;
</script>
</li>
<li class="menu-item">
<?php gn_custom_taxonomy_dropdown( 'gntx_figure', 'figures', 'Choisir une personne', '32,67,81,90,80'); ?>
<script type="text/javascript">
var menuFigure = document.getElementById("figures");
function onCatChange() {
if ( menuFigure.options[menuFigure.selectedIndex].value != -1 ) {
location.href = "<?php echo home_url();?>/figures/"+menuFigure.options[menuFigure.selectedIndex].value+"/";
}
}
menuFigure.onchange = onCatChange;
</script>
</li>
</ul>
</div>
</nav>
<?php // NE PAS METTRE CETTE BALISE PHP
/**************************
* Menu déroulant pour les taxonomie
* Affiche le menu déroulant
* en fonction des paramètres
**************************/
// use: gn_custom_taxonomy_dropdown( 'custom_taxo' )
function gn_custom_taxonomy_dropdown( $taxonomy, $id, $option, $exclude ='' ) {
$terms = get_terms( $taxonomy, array('exclude' => $exclude ) );
if ( $terms ) {
printf( '<select name="%s" class="postform" id="%s">', esc_attr( $taxonomy ), esc_attr( $id ) );
printf( '<option value"">%s</option>', esc_attr( $option ) );
foreach ( $terms as $term ) {
if ( $term->count < 2) continue;
printf( '<option value="%s">%s (%s)</option>', esc_attr( $term->slug ), esc_html( $term->name ), esc_html($term->count) );
}
print( '</select>' );
}
} // function gn_custom_taxonomy_dropdown()
<!-- Structure et fonction pour le menu de la taxonomie -->
<li class="menu-item">
<?php gn_custom_taxonomy_dropdown( 'gntx_lieux', 'lieux', 'Choisir un lieu', '71'); ?>
<script type="text/javascript">
var menuLieu = document.getElementById("lieux");
function onCatChange() {
if ( menuLieu.options[menuLieu.selectedIndex].value != -1 ) {
location.href = "<?php echo home_url();?>/lieux/"+menuLieu.options[menuLieu.selectedIndex].value+"/";
}
}
menuLieu.onchange = onCatChange;
</script>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment