Skip to content

Instantly share code, notes, and snippets.

@maximejobin
Created July 8, 2015 20:06
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 maximejobin/f7a627e5b7ae0f58e8a2 to your computer and use it in GitHub Desktop.
Save maximejobin/f7a627e5b7ae0f58e8a2 to your computer and use it in GitHub Desktop.
Afficher les X derniers éléments pour un Custom Post Type
<?php
$nombre = 3; // Nombre d'éléments à afficher
$type = 'recette'; // À modifier selon le type du CPT
$new_loop = new WP_Query( array(
'post_type' => $type,
'showposts' => $nombre
) );
if ( $new_loop->have_posts() ) :
while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?>
<!-- HTML à afficher pour chaque recette -->
<h2><?php the_title(); ?></h2>
<?php endwhile;?>
<?php else: ?>
Aucun élément à afficher...
<?php endif; ?>
<?php wp_reset_query(); ?>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment