• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Isocèle Web Design

Création de sites Web

  • Fr
  • Esp
  • Clients
  • Présentation
  • DEVIS
  • Contact

Page d’Archives avec répartition selon la taxonomie

7 janvier 2020 by

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();

  • Header coulissant avec Headroom

  • Les bases pour améliorer le positionnement / Search Engine Optimization

  • 7 Plugins Gratuits Indispensables

  • Hébergement Web : les requis pour WordPress

  • Page d’Archives avec répartition selon la taxonomie

  • Afficher un Champ personnalisé via un Shortcode

  • Afficher une taxonomie personnalisée via un shortcode

  • Custom Post Archive avec Custom Taxonomy et Custom Fields

  • Avez-vous vraiment besoin d’acheter un Thème ?

Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Tumblr
Tumblr
Email this to someone
email

Filed Under: Avancé, Tutoriel Tagged With: archive, php, taxonomie

Footer

Isocèle Web Design

Rue Mathis
75019 Paris
FRANCE

Carrer Torrent de l'Olla
08012 Barcelona
ESPAÑA

isocele.webdesign@gmail.com

Liens

Tutoriels

Politique de confidentialité

Réseaux sociaux

Suivez-nous sur...

Partagez sur...

Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Tumblr
Tumblr
Email this to someone
email

Copyright © 2021 · Genesis Sample Theme on Genesis Framework · WordPress · Log in