[1] Bickerton, Derek. Adam’s tongue: how humans made language, how language made humans. Macmillan, 2009.
[2] Számadó, Szabolcs, and Eörs Szathmáry. “Selective scenarios for the emergence of natural language.” Trends in Ecology & Evolution 21.10 (2006): 555-561.
[3] Odling-Smee, John, and Kevin N. Laland. “Cultural niche construction: evolution’s cradle of language.” The prehistory of language 11 (2009): 99.
add_filter( 'getarchives_join', 'lf_getarchives_join', 10, 2 );
$out = wp_get_archives( [
'type' => 'yearly',
'show_post_count' => true,
'echo' => false,
'order' => 'ASC',
] );
remove_filter( 'getarchives_join', 'lf_getarchives_join' );
// 生成されたリストから年と投稿数を切り出す
preg_match_all(
'|\>(\d+)\</a.+\((\d+)\)\</li|',
$archives,
$matches
);
// 年を数値に変換
$years = array_map( 'intval', $matches[1] );
// 年別投稿数を数値に変換して累積値を取得
$counts = [];
foreach ( $matches[2] as $i => $match ) {
$counts[] += (int)$match + ( $counts[$i-1] ?? 0 );
}
function lf_getarchives_join( $sql_join, $parsed_args ) {
return "
JOIN wp_term_relationships AS tr ON wp_posts.ID = tr.object_id
JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category'
JOIN wp_terms AS t ON tt.term_id = t.term_id AND t.name='list'
";
}
そして $years を横軸に、$counts を縦軸にしたグラフを描画させます。
2. SQLを直接発行する
JOIN句をずらずら書かなければいけないのなら、標準関数を使わずSQLを発行するのも手です。
$query = "SELECT YEAR(post_date) AS year, COUNT(post_date) AS count
FROM wp_posts AS p
JOIN wp_term_relationships AS tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'category'
JOIN wp_terms AS t ON tt.term_id = t.term_id AND t.name='list'
WHERE p.post_status='publish' AND p.post_type='post'
GROUP BY YEAR(post_date)";
$publists = $wpdb->get_results( $query );
// グラフの横軸(年)と縦軸(累積投稿数)データを取得
foreach ( $publists as $i => &$publist ) {
// 前年の投稿数(初年度の前年は0)を加算
$publist->count += ( $publists[$i-1]->count ?? 0 );
$years[] = $publist->year;
$counts[] = $publist->count;
}