Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

fr:Creating an Archive Index

Page d'accueil du Codex en français - Télécharger WordPress en français
Les utilisateurs francophones se retrouvent sur le site WordPress-Francophone, notamment sur son forum d'entraide.

This page is marked as incomplete. You can help Codex by expanding it.

Introduction

So you want a single page with links to all your archived entries, arranged just so to form the main gateway into your blog's past. With the WordPress 1.5 theme system, you can create template files to customize this archive gateway for each theme you use.

Or, maybe you're just wondering how to use the archives.php template file that's included with the WordPress Default Theme.

This article describes both those things. The method outlined here can also be used to make other specialized pages that are integrated with the WordPress theme system: a links page, site index, or anything else your heart desires.

Création du Modèle du Sommaire des Archives et des Pages

To set up a separate archive index in a way that plays with the Version 1.5 theme system, you'll need to create it as a Page, and assign it a special template.

Le Modèle (archives.php)

Start off with a simple template called archives.php, stored in your theme's directory. The WordPress Default Theme includes such a template, and it makes a good starting point.

Technically, the template can be called almost anything (see these two lists for names you should not use; these are special file names WordPress reserves for specific purposes). However, using a standard name for your template will make it easier to change your blog's theme or distribute your theme and template to the WordPress community. It's also possible to display a large archive index using one of the all-purpose templates (like index.php or category.php) and the is_page function, but again, taking advantage of the theme system's modularity makes it easier for others (and for you!) to edit your template later.

For more information on creating templates, see Template Tags, particularly wp_get_archives.

La Page des Archives

pour WordPress 1.5

Upload the archives.php in your theme directory (wp-content/themes/themename/). Then from the Admin Panel, Write > Write Page, and choose Add a New Page:

  1. Give your new archives Page a suitable title like Archive Index. Leave the Page content blank.
  2. Under Custom Fields, select _wp_page_template from the dropdown. Leave the Key field blank, and enter archives.php into the Value field.
  3. Click Add Custom Field.
  4. Voila! Your archive index can be accessed at http://example.com/index.php?pagename=archive-index.

pour WordPress 1.5 et +

Upload the archives.php in your theme directory (wp-content/themes/themename/). Then from the Admin Panel, Write > Write Page

  1. Give your new archives Page a suitable title like Archive Index. Leave the Page content blank.

In the sidebar open the //Page templates// box, and select the //Archives// template. After saving it you will see a new item in your pages list, click on it, and enjoy!

Personnalisation de Vos Archives

There are a variety of techniques to customize your Archive Index page. Some involve incorporation of plugins or PHP code to create customized lists of archived posts, and others provide more interesting ways of displaying your archives.

Liste des Archives par Année

You can set your archives up to be displayed by the year, such as:

Archives

  • 2007
  • 2006
  • 2005
  • 2004

To list your archives by year instead of by month, use the following code, in which a query to the database is made to collect and sort the posts by year, then display them as links with the get_year_link() template tag:

<ul><li><h2>Archives</h2>
<ul>
<?php
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) : 
?>
<li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li>
<?php endforeach; ?>
</ul>
</li></ul>

For versions of WordPress before 2.1, use this for your $years query:

$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");

Mise en Place des Redirections

If you're using Permalinks, WordPress will generate a new set of rewrite rules for your new Page. You may need to update your .htaccess file by hand, if WordPress is unable to do so automatically. See Using Permalinks for more information.

These automatic rules are based on your Page title or "slug": If your Page is named Archive Index, you'll be able to see it at http://example.net/your-wordpress-dir/archive-index/.

Problèmes avec la Génération Automatique des fichiers .htaccess

If your archive index Page has a slug that's the same as part of your permalink structure - e.g., your Page is named Archives, and your permalinks are set up as /archives/%post-id%/ or /archives/%year%/%monthnum%/%day%/%postname%/ - WordPress will create conflicting rewrite rules. This can cause your monthly/category archives to be displayed using your archive index template.

There are two ways to avoid this problem:

  1. Use a different name for your archive index Page
  2. Don't allow WordPress to automatically manage your .htaccess file.

Pour en Savoir Plus

Plugins Utile

Sujets de Support sur les Forums de WordPress

Exemples Intéressant d'Index d'Archives

  • Hit or Miss - Flickr-style weighted categories and keywords.
  • Engadgeted - The Heat Map plugin in action.