Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // securité
- defined('ABSPATH') or die('Restricted Area');
- // Affichage du header du thème
- get_header();
- // Quelques variables à modifier
- $taxonomy = 'category';
- $post_type = 'post';
- // nom du transient
- $transient_name = 'content-archive-'.$post_type.'-'.$taxonomy;
- // lecture du transient
- $my_content = get_transient( $transient_name );
- // Si on a du contenu
- if ( false !== $my_content ) {
- echo $my_content;
- } else { // sinon on va le générer
- ob_start(); // mise en mémoire tampon
- ?>
- <header class="page-header">
- <h1 class="container">
- <?php
- // récupération de l'objet du type de post
- $post_type_obj = get_post_type_object( $post_type );
- // affichage de son nom
- echo apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
- ?>
- </h1>
- </header>
- <div class="content">
- <div class="container">
- <?php
- // récupération des termes de ma taxo
- $term_args = array(
- 'orderby' => 'name',
- 'order' => 'ASC'
- );
- $terms = get_terms( $taxonomy, $term_args );
- // si j'ai bien des termes
- if ( $terms ) {
- // On boucle sur ces termes
- foreach( $terms as $term ) { ?>
- <div class="row">
- <h1 class="term-title">
- <?php
- // on affiche le nom du terme
- echo $term->name;
- ?>
- </h1>
- <?php
- // on replace le pointeur du tableau au début
- reset( $GLOBALS['wp_query']->posts );
- // on parcours les itérations des articles de la main query
- foreach( $GLOBALS['wp_query']->posts as $_post ) {
- // si cet article contient le terme, on traite ce contenu
- if ( has_term( $term, $taxonomy, $_post ) ) {
- ?>
- <div>
- <?php
- // si il a une image à la une, ...
- if ( has_post_thumbnail( $_post->ID ) ) {
- // ... on l'affiche ...
- echo get_the_post_thumbnail( $_post->ID, 'thumbnail' );
- }
- // ... puis son lien et titre.
- ?>
- <h2><a href="<?php echo get_the_permalink( $_post->ID ) ?>" rel="bookmark" title="<?php the_title_attribute( array( 'post' => $_post ) ); ?>"><?php echo get_the_title( $_post ); ?></a></h2>
- </div>
- <?php
- }
- }
- ?>
- </div>
- <?php
- }
- }
- ?>
- </div>
- </div>
- <?php
- // récupération du tampon
- $my_content = ob_get_contents();
- // on affiche et efface le tampon
- ob_end_flush();
- // on mets ce contenu dans un transient non timé
- set_transient( $transient_name, $my_content );
- }
- // Affichage du footer du thème
- get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement