[insert_php]
$count_posts = wp_count_posts();
// echo date(‘l, F j, Y \a\t G:i:s’);
$args = array(
‘type’ => ‘yearly’,
‘show_post_count’ => true
);
echo ‘

‘,’Počet všech reportů za každý rok’,’

‘;
wp_get_archives($args);
echo ‘
‘;
[/insert_php]

[insert_php]

echo ‘

‘,’Detail podle ročníků’,’

‘;
$oldest = get_posts( ‘post_type=post&post_status=publish&posts_per_page=1&order=ASC’ );
$oldest_date = $oldest[0]->post_date;

$first_date = date(‘Y’, strtotime($oldest_date));
$todays_date = date(‘Y’);

$year_range = range($todays_date, $first_date);

foreach ($year_range as $year) { // dynamic year-based tables
echo ‘

‘ . $year . ‘

‘;
$terms = get_terms(‘category’);

if ( !empty( $terms ) && !is_wp_error( $terms ) ) { // table body

echo ‘

‘;
echo ‘

‘;

$posts_count = array(); // Holds all term post counts in an array
$term_names = array(); // Holds all term names in an array

foreach($terms as $term) {
$term_names[] = $term->name; //Collects term names and send them to an array

$args = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’,
‘year’ => $year,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘category’,
‘field’ => ‘slug’,
‘terms’ => $term->slug,
‘include_children’ => false
),
),
);

$yearly_posts_per_term = new WP_Query($args);
$posts_count[] = $yearly_posts_per_term->post_count; //Collects post counts and send them to an array

} // endforeach

unset($term);

}

$total_posts = array_sum($posts_count); //Use array_sum to add up all the separate post counts

$combine = array_combine($term_names,$posts_count); //Use array_combine to combine term names and post counts into assosiative array
arsort($combine);
foreach ($combine as $term_name=>$count) {

$percentage = round( (($count / $total_posts)*100), 2 ); //Calculate the percentages of each term post cound to total year post count

echo ‘

‘;
}
//
// echo ‘
//

//

//

//

//

//

// ‘;

echo ‘

Klasifikační položka Počet výskytů/přiřazení
‘.$term_name.’ ‘.$count.’
Posts total ‘.$total_posts.’

‘;
} // end of year-based list

[/insert_php]