• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Isocèle Web Design

Isocèle Web Design

Création de sites Web

  • Réalisations
  • DEVIS
  • Contact

Page d’Archives avec répartition selon la taxonomie

Voici une jolie boucle avec le Framework Genesis et le Plugin CPTUI.

On a un type d’articles personnalisé “Potager” pour lequel on a créé une taxonomie personnalisée “Saison”.

On souhaite afficher dans la même archive les différents “Potager” mais selon la “Saison” comme dans cet exemple:

Printemps

  • Laitue
  • Carotte
  • Persil

Eté

  • Fraises
  • Concombre

Automne

  • Pommes
  • Artichaud
  • Petits Pois

Hiver

  • Pommes de Terre

Tout d’abord, créer le fichier archive-potager.php dans le dossier du Thème Enfant.

Voici la boucle à insérer:

<?php

//* Template Name: Potager Archive */
remove_action ('genesis_loop', 'genesis_do_loop'); /

add_action('genesis_loop', 'potager1_custom_loop');
function potager1_custom_loop() {
  echo '<h2>Printemps</h2>';
  
  $args = array('saison' => 'printemps',
                'post_type' => 'potager', 
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'posts_per_page'=> '6', // exemple pour un maximum de 6 articles Potager dans cette section.
                );
  $loop = new WP_Query( $args );
  if( $loop->have_posts() ):
  while( $loop->have_posts() ): $loop->the_post(); global $post;
 
          echo '<div id="potpot">';
              echo '<a href="' . get_permalink() .'">';
                 echo '<h3>' . get_the_title() . '</h3>';
                 echo '<div class="pays">'.genesis_get_custom_field( 'pays' ) .'</div>';
              echo '</a>';
         echo '</div>';
 
 endwhile;
 endif;
 
}
/////
add_action('genesis_loop', 'potager2_custom_loop');
function potager2_custom_loop() {
  echo '<h2>Eté</h2>';
  
  $args = array('saison' => 'ete',
                'post_type' => 'potager', 
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'posts_per_page'=> '6', // exemple pour un maximum de 6 articles Potager dans cette section.
                );
  $loop = new WP_Query( $args );
  if( $loop->have_posts() ):
  while( $loop->have_posts() ): $loop->the_post(); global $post;
 
          echo '<div id="potpot">';
              echo '<a href="' . get_permalink() .'">';
                 echo '<h3>' . get_the_title() . '</h3>';
                 echo '<div class="pays">'.genesis_get_custom_field( 'pays' ) .'</div>';
              echo '</a>';
         echo '</div>';
 
 endwhile;
 endif;
 
}
/////
add_action('genesis_loop', 'potager3_custom_loop');
function potager3_custom_loop() {
  echo '<h2>Automne</h2>';
  
  $args = array('saison' => 'automne',
                'post_type' => 'potager', 
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'posts_per_page'=> '6', // exemple pour un maximum de 6 articles Potager dans cette section.
                );
  $loop = new WP_Query( $args );
  if( $loop->have_posts() ):
  while( $loop->have_posts() ): $loop->the_post(); global $post;
 
          echo '<div id="potpot">';
              echo '<a href="' . get_permalink() .'">';
                 echo '<h3>' . get_the_title() . '</h3>';
                 echo '<div class="pays">'.genesis_get_custom_field( 'pays' ) .'</div>';
              echo '</a>';
         echo '</div>';
 
 endwhile;
 endif;
 
}
//////
add_action('genesis_loop', 'potager4_custom_loop');
function potager4_custom_loop() {
  echo '<h2>Hiver</h2>';
  
  $args = array('saison' => 'hiver',
                'post_type' => 'potager', 
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'posts_per_page'=> '6', // exemple pour un maximum de 6 articles Potager dans cette section.
                );
  $loop = new WP_Query( $args );
  if( $loop->have_posts() ):
  while( $loop->have_posts() ): $loop->the_post(); global $post;
 
          echo '<div id="potpot">';
              echo '<a href="' . get_permalink() .'">';
                 echo '<h3>' . get_the_title() . '</h3>';
                 echo '<div class="pays">'.genesis_get_custom_field( 'pays' ) .'</div>';
              echo '</a>';
         echo '</div>';
 
 endwhile;
 endif;
 
}

genesis();

Primary Sidebar

  • Tutoriels
  • Les bases
  • Avancé

archive bases champ personnalise child theme css custom field genesis gratuit headroom hebergement indispensable js php plugin plugins positionnement script SEO shortcode taxonomie technique theme tutoriel Wordpress

Footer


Politique de confidentialité

Isocèle Web Design
Rennes
France
contact(at)isocele-webdesign.fr

Font Basteleur by Keussel. Distributed by velvetyne.fr