13 Les Jardins d'Hélios, 82230 Léojac

Modifier une boucle WordPress

Les boucles WordPress ne sont pas forcément simples à personnaliser, voici quelques exemples de codes glanés sur la toile:

Always use get_posts … . Remove the arguments that you don’t use on the array below.

				
					$args = array(
'posts_per_page' => 5000,
'offset' => 0,
'category' => ,
'orderby' => 'post_date',
'order' => 'ASC',
'include' => ,
'exclude' => ,
'meta_key' => ,
'meta_value' => ,
'post_type' => 'post',
'post_mime_type' => ,
'post_parent' => ,
'post_status' => 'publish',
'suppress_filters' => true );
$posts = get_posts($args);
foreach ($posts as $post) :
?><div class="">
<a href="<?php the_permalink();?>">
<?php
echo the_title();
echo the_post_thumbnail(array(360,360));
the_excerpt('more text');
?></a></div>
<?php endforeach; ?>
<?php
				
			

Autre exemple:

https://codex.wordpress.org/Category_Templates

You can also use Conditional_Tags in order to create archives that respond to conditions set by the URL or context. For instance, if you would like to ensure that when a user visits http://yourblog.com/2008/02/ it will show posts from February of 2008 first, simply add this code to your archive.php file.

				
					<?php if (have_posts()) : ?>
<?php if (is_month()){ $year = get_the_time('Y'); $month = get_the_time('m'); $the_query = new WP_Query( 'monthnum=$month&year=$year&$cat=5' ); // The Loop while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '
<li>' . get_the_title() . '</li>

';
endwhile;

/* Restore original Post Data
* NB: Because we are using new WP_Query we aren't stomping on the
* original $wp_query and it does not need to be reset.
*/
wp_reset_postdata();
?>
				
			
Partager cet article:

Autres articles