Bonjour!
I’ve tried the 3 solutions and finally used the one of Michael in the topic 337364
To filter the actual category, I have included a variable
<?php $currentCat = get_query_var(‘cat’); ?>
and an argument
‘category__in’ => array($currentCat)
It works!
Sometime, a lonely title get lost and doesn’t appear properly alphabetically. I’ve search for forgotten spaces in the titles but could not find any real reason.
Anyway, THANKS a lot (I will check If I can also bring a contribution by the translations into French).
Here is the result https://valentine-meunier.de/wordpress/
And here is the code
<?php $currentCat = get_query_var('cat'); ?>
<?php
$args=array(
'orderby' => 'date',
'order' => 'ASC',
'posts_per_page' => 1,
'caller_get_posts'=>1,
);
$oldestpost = get_posts($args);
$args=array(
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 1,
'caller_get_posts'=>1,
);
$newestpost = get_posts($args);
if ( !empty($oldestpost) && !empty($newestpost) ) {
$oldest = mysql2date("Y", $oldestpost[0]->post_date);
$newest = mysql2date("Y", $newestpost[0]->post_date);
for ( $counter = intval($newest); $counter >= intval($oldest); $counter = $counter - 1) {
$args=array(
'year' => $counter,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'caller_get_posts'=>1,
'category__in' => array($currentCat)
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<h2 class="jahr">' . $counter . '</h2>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h2 class="author"><?php the_title(); ?></h2>
<div class="entry">
<?php the_content() ?>
</div>
<?php
//the_content('Read the rest of this entry »');
endwhile;
} //if ($my_query)
wp_reset_query(); // Restore global post data stomped by the_post().
}
}
?>