我想这样做:
首先,简单地计算年份:
// this is a multipurpose function I made, and it\'s quite self explanatory
function get_years($post_type, $order = "ASC", $exclude = array(), $future = true, $taxonomy = null, $term = null){
global $wpdb;
$type = ($post_type) ? $post_type : \'post\';
$status = ($future) ? " (\'publish\', \'future\') " : " (\'publish\') ";
$exclude = (!empty($exclude)) ? " AND YEAR(post_date) NOT IN (" . implode(\',\',$exclude) . ") " : "";
return $wpdb->get_results($wpdb->prepare("
SELECT YEAR(post_date) AS `y`, count(ID) as posts_count
FROM $wpdb->posts p
INNER JOIN $wpdb->term_relationships rel ON p.ID = rel.object_id
INNER JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = rel.term_taxonomy_id
INNER JOIN $wpdb->terms t ON tt.term_id = t.term_id
WHERE
p.post_type = %s
AND tt.taxonomy = %s
AND t.slug = %s
AND post_status IN " . $status . "
$exclude
GROUP BY y
ORDER BY post_date " . $order,
$post_type,
$taxonomy,
$term
),OBJECT_K);
}
然后,通过这些年来的cicle和建立permalinks:
get_year_link($year); // this is wp.
它适用于帖子,否则可以通过更“手动”的方式构建类似的内容:
home_url(user_trailingslashit(\'write some path here\' . $year));