-
-
Save maximejobin/f7a627e5b7ae0f58e8a2 to your computer and use it in GitHub Desktop.
Afficher les X derniers éléments pour un Custom Post Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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