Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coupe WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Comment créer une page d’archive de Type de publication personnalisé dans WordPress

Note éditoriale : Nous percevons une commission sur les liens des partenaires sur WPBeginner. Les commissions n'affectent pas les opinions ou les évaluations de nos rédacteurs. En savoir plus sur Processus éditorial.

Vous souhaitez créer une page d’archive de type publication personnalisée dans WordPress ?

Normalement, les types de publication personnalisés de WordPress utilisent le modèle d’archive de votre thème. Vous pouvez également créer votre propre page d’archive personnalisée pour vos types de publication.

Dans cet article, nous allons vous afficher comment créer facilement des pages d’archives de types de publication personnalisés dans WordPress.

Creating a custom post type archive page in WordPress

Qu’est-ce qu’une page d’archive de type de publication personnalisé dans WordPress ?

La page d’archive d’un type de publication personnalisé permet aux utilisateurs/utilisatrices de voir tous les articles classés sous un type de publication personnalisé particulier.

Lorsque vous créez un type de publication personnalisé, WordPress génère automatiquement des pages d’archives pour ce type de publication. La page d’archive est une liste de tous les articles associés à ce type de publication personnalisé. Vous permettez ainsi aux internautes de parcourir et d’accéder facilement au contenu de ce type de publication.

Par défaut, WordPress propose deux types de publication couramment utilisés, les  » Posts » et les « Pages« . Les extensions WordPress peuvent également créer leurs propres types de publication.

Par exemple, WooCommerce ajoute un nouveau type de publication appelé Produits à votre site WordPress.

De même, vous pouvez créer des types de publication personnalisés et les utiliser pour gérer différents types de contenu.

Après avoir créé votre type de publication personnalisé, vous pouvez l’utiliser dans la zone d’administration de WordPress. Cependant, c’est votre thème WordPress qui est responsable de l’affichage de tout votre contenu.

Si votre thème n’a pas de modèle pour un type de publication particulier, WordPress utilisera le modèle d’archive par défaut pour afficher la page d’archive de n’importe quel type de publication.

Archives page for a custom post type

Pour en savoir plus, consultez notre guide sur la hiérarchie des modèles WordPress et comment les utiliser dans votre thème WordPress.

Maintenant, si vous souhaitez apporter des modifications à l’affichage de la page d’archive de votre type de publication personnalisé, vous pouvez le faire en créant un modèle personnalisé.

Ceci étant dit, voyons comment créer facilement une page d’archive de type publication personnalisée dans WordPress.

Activer l’archivage pour votre Type de publication personnalisé dans WordPress

Avant de pouvoir créer et utiliser la page d’archive du type de publication personnalisé, assurez-vous d’abord que la fonctionnalité d’archive est activée dans votre type de publication personnalisé.

Par exemple, si votre type de publication personnalisé s’appelle films et que vous avez activé les permaliens SEO-friendly, l’archive de votre type de publication sera libellée comme suit :

https://example.com/movies

Si vous obtenez une page d’erreur 404 lorsque vous visitez cette page, c’est que la fonctionnalité d’archive n’est pas activée pour votre type de publication.

404 error for custom post type archive page

Maintenant, si vous avez utilisé une extension pour générer votre type de publication personnalisé, alors vous pouvez simplement le modifier à cet endroit et activer la fonctionnalité d’archive.

Par exemple, dans l’extension CPT UI, vous pouvez modifier votre type de publication personnalisé et activer la fonctionnalité « Has Archive » dans les Réglages du type de publication.

CPT UI turn on archive

En revanche, si vous avez utilisé du code pour générer votre type de publication personnalisé, vous devrez modifier ce code pour activer les modifications.

Voici un bref exemple du code permettant de générer un type de publication. Vous pouvez voir que la dernière ligne a un attribut supplémentaire pour activer les pages d’archives :

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'movies',
        array(
            'labels' => array(
                'name' => __( 'Movies' ),
                'singular_name' => __( 'Movie' )
            ),
        'public' => true,
        'has_archive' => true,
        )
    );
}

Après avoir ajouté la fonctionnalité has_archive, vous pourrez voir la page d’archive de votre type de publication personnalisé au lieu d’obtenir une erreur de WordPress.

Outil de personnalisation de votre page d’archive de type de publication personnalisé

Pour certains utilisateurs/utilisatrices, le modèle d’archive par défaut conviendra parfaitement. Il listera tous les articles que vous avez publiés sous votre type de publication personnalisé.

Toutefois, certains utilisateurs/utilisatrices voudront peut-être la modifier un peu pour qu’elle ait un aspect différent de celui des archives de votre blog et d’autres pages d’archives.

Vous pouvez le faire en ajoutant un modèle personnalisé pour votre type de publication personnalisé à votre thème WordPress.

Tout d’abord, vous devez vous connecter à votre site WordPress à l’aide d’un client FTP ou via l’application Gestionnaire de fichiers de votre panneau de contrôle de l’hébergeur.

Une fois connecté, vous devez naviguer jusqu’au dossier /wp-content/themes/votre-thème-courant/.

Download archive template

À partir de là, vous devez télécharger le fichier archive.php sur votre ordinateur.

Une fois téléchargé, vous devez renommer le fichier en archive-{posttype}.php, où {posttype} est le nom de votre type de publication personnalisé.

Par exemple, si votre Type de publication personnalisé s’appelle films, vous devrez le renommer en archive-movie.php.

Rename archive template

Vous pouvez maintenant ouvrir ce fichier à l’aide d’un éditeur de texte tel que le Bloc-notes pour y apporter des modifications.

Ce fichier contient déjà tout le code nécessaire pour afficher le contenu du type de publication personnalisé. Vous pouvez y ajouter tout le code que vous souhaitez ou modifier la mise en page du Modèle existant.

Astuce : si vous avez besoin d’aide, consultez notre aide-mémoire sur le développement de thèmes WordPress pour les débutants.

Lorsque vous êtes satisfait de vos modifications, n’oubliez pas d’enregistrer le fichier.

Ensuite, vous devez téléverser ce fichier dans le dossier de votre thème WordPress à l’aide du FTP ou de l’application Gestionnaire de fichiers.

Vous pouvez maintenant visiter la page d’archive de votre type de publication personnalisé pour voir vos modifications en action.

Custom archive template preview

Créer une page d’archive avec un type de publication personnalisé en utilisant SeedProd

Pour cette méthode, nous allons utiliser SeedProd. C’est le meilleur plugin de constructeur de page WordPress sur le marché et il vous permet de créer facilement des pages personnalisées pour votre site.

Il est livré avec une interface drag-and-drop qui vous autorise à concevoir facilement votre page de type publication personnalisée sans écrire de code. Vous pouvez également utiliser Outil de personnalisation pour concevoir d’autres pages sur votre site ou même créer un thème personnalisé à partir de zéro.

Tout d’abord, vous devez installer et activer l’extension SeedProd. Pour plus de détails, consultez notre guide étape par étape sur l ‘installation d’une extension WordPress.

Lors de l’activation, vous devez saisir votre clé de licence SeedProd. Vous trouverez cette information dans votre compte sur le site de SeedProd.

SeedProd license key

Ensuite, vous devez aller à SeedProd  » Landing Pages.

À partir de là, cliquez sur le bouton  » Ajouter une nouvelle page atterrissage  » pour commencer.

Add new landing page

Ensuite, vous devez choisir un modèle pour votre page.

S’il existe un modèle similaire à la conception de votre site, vous pouvez l’utiliser ou commencer avec un modèle vierge.

Choose template

Ensuite, vous devez donner un nom à votre page et choisir une URL.

Confirmez que vous utilisez quelque chose qui représente votre type de publication personnalisé.

page name and URL

Vous accéderez ainsi à l’interface du constructeur de page.

Vous pouvez choisir une mise en page pour commencer, puis commencer à ajouter des blocs dans la colonne de gauche.

Page builder user interface

Commençons par ajouter le bloc Publications pour afficher les articles de votre type de publication personnalisé.

Il suffit de faire glisser et de déposer le bloc Publications de la section Avancés sur votre page.

Add posts block

Par défaut, le bloc des publications affiche les articles de votre blog.

Cliquez sur les Réglages du bloc, puis sélectionnez votre type de publication dans la section Requête par type de publication.

Select post type

Après cela, vous pouvez passer en revue d’autres options pour activer l’image en avant, modifier la taille de l’extrait, et plus encore.

Lorsque vous avez terminé les réglages du bloc de publication, vous pouvez passer à l’onglet Sections et ajouter un en-tête ou un pied de page à votre mise en page.

Edit your post type page

Une fois les modifications terminées, vous pouvez publier votre page.

Il suffit de cliquer sur la flèche déroulante située à côté du bouton Enregistrer et de sélectionner « Publier ».

Publish your custom page

Vous pouvez maintenant visiter votre page personnalisée en cliquant sur l’onglet Prévisualisation pour la voir en action.

Voici à quoi ressemble la page d’archive de notre type de publication personnalisé sur notre site de test.

Custom archive page template created with SeedProd

Vous pouvez également ajouter cette page à votre menu de navigation ou continuer à la modifier pour l’optimiser davantage.

Exemples de pages d’archive de type de publication personnalisé

L’utilisation d’un Modèle personnalisé pour votre page d’archive de type publication vous permet de la personnaliser en fonction de vos besoins.

Par exemple, vous pouvez retirer la colonne latérale, modifier la mise en page de la page et fournir plus de contexte pour rendre la page d’archive plus attrayante.

Voici quelques exemples de pages d’archives de type personnalisation avec leurs propres modèles personnalisés.

La pageOutil de personnalisation est un type de publication personnalisé qui utilise son propre modèle d’archive.

Custom post type archive page example - WPBeginner Deals

Nous utilisons également un modèle personnalisé pour notre section Glossaire WordPress.

Il s’agit également d’un type de publication personnalisé.

Glossary page using a custom post type archive page

Nos amis de MemberPress utilisent un modèle d’archive de type personnalisé pour leur section de modules.

Vous pouvez voir l’exemple dans la capture d’écran ci-dessous.

MemberPress addons custom post type

Nous espérons que cet article vous a aidé à apprendre comment créer facilement une page d’archive de type publication personnalisée. Vous pouvez également consulter notre liste des extensions et outils WordPress incontournables pour les sites professionnels ou notre comparaison experte des meilleurs fournisseurs de VoIP pour les entreprises.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Divulgation : Notre contenu est soutenu par les lecteurs. Cela signifie que si vous cliquez sur certains de nos liens, nous pouvons gagner une commission. Consultez comment WPBeginner est financé, pourquoi cela compte et comment vous pouvez nous soutenir. Voici notre processus éditorial.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

L'ultime WordPress Toolkit

Accédez GRATUITEMENT à notre boîte à outils - une collection de produits et de ressources liés à WordPress que tous les professionnels devraient avoir !

Reader Interactions

53 commentairesLaisser une réponse

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Fabio says

    Hi there
    I’ve created the Archive Page adding the archive-custom.php file to the file manager of my website as explained here.
    Only, I have no way to customize it but using the theme embedded Customize section.
    I thought instead I was going to be able to customize the CPTs Archive Page as all other pages, i.e. with a page builder (Elementor in my case).
    Where did I go wrong (in case I did)?

    • WPBeginner Support says

      It would depend on your specific theme for what customization options are available which is why we recommend SeedProd in our article to give a drag and drop customization option.

      Administrateur

  3. Ifeoluwa Ajetomobi says

    Hi, love is step by step guide, but I would love to know how to create an archive template page for a book directory, instead of using any filter to navigate categories, I will love to learn how to create a custom archive page to display each categories.
    Eg. Like a business listing site, people can filter by location, business type but I will love to know how to create archive page for it instead of using filter

    Thank you

  4. Leo Brady says

    Hi there, thanks for your Custom Post blogs!

    I have successfully created a custom post type and associated Archive page.

    I now want to display the custom posts on the main Archive page as well, so that if for example someone click a Category link they see the regular and custom posts that have that particular Category.

    What is the best way to achieve this?

  5. Carrie Lewis says

    I have a quick question. I am trying to build a FAQ page and I would like just the questions to show on the main archive page and not the content. So when they click on the questions it will take them to the content page itself.

    Also is there a way to not show the authors name in the posted content. I am not a programmer but am learning. Thanks. :-)

  6. Monique says

    Everything works but how do you give your custom post type another design as your other posts? Can you use it with a single.php file that sends each post to its own single-[tag or category].php file? I tried this out and get the right single post URL in the location bar but the wrong content on the page.

  7. dragoescu alin says

    Hello, I just creat a new file archive for a new type. The name of new typw it’s firma.
    The archide page it’s call archive-firma.php . All run good but i realy don’t know where i can insert new php code.

    I want to add new code because i use ACF codes.
    please any help ?

    The page code it’s:

    <?php
    the_archive_title( '’,  » );
    the_archive_description(  »,  » );
    ?>

    __( ‘Previous page’, ‘twentysixteen’ ),
    ‘next_text’ => __( ‘Next page’, ‘twentysixteen’ ),
    ‘before_page_number’ =>  » . __( ‘Page’, ‘twentysixteen’ ) . ‘ ‘,
    ) );

    // If no content, include the « No posts found » template.
    else :
    get_template_part( ‘template-parts/content’, ‘none’ );

    endif;
    ?>


  8. Rima says

    Hello
    It’s ammazing completely job .
    Congractulations .
    Can you please help me make my own archiving for the kids club .to save all things in safety way .
    Can you help me ??

  9. Essekia Paul says

    I think, when working on really extensive websites with a lot of post types, taxonomies, terms, it is better to manage archives with something like the Elementary plugin.

    This also makes it easier to maintain / separate the content / design of archives.

  10. Hariharakumar says

    My category archives for CPT are displaying in archive.php instead of archive-{CPT}.php what should i do now? please help

    • Rafael Cavalcante says

      Replace {CPT} with the name of your custom post type.

      IE.:
      For « register_post_type(‘brand’) », your template will be archive-brand.php

  11. Max says

    WordPress files and their editing was just like a scare forest where i can’t find my desired code. PHP was just like a mountain that can’t be handled by me. but with this blog’s post give a confidence and a boost to start.
    Now i have hand on almost from installing to deploying WordPress website/blog.
    Thanks and Honors for Mr. Balkhi

  12. Jeremy says

    what if I already have a page at yoursite/deals which has content on it. What would the url to my category’s archive page be?

    • Jouke Nienhuis says

      You must not think in real internetlinks or URI as they are called. In WordPress you have an option to rewrite the url, so that it links directly to the post name or category archive. In the address bar, you normally see an address pointing to a file, or if you have it directed to a directory, like it looks in your example, it can take its index.html or index.php file in that directory. But in a WordPress site that address is cloaked and in reality it takes you to archive-deals.php. So no conflicts here. You have to change the thinking form normal linking to an address to a WordPress linking.

  13. linx says

    Never mind, i solved my problem by adding this to my functions.php

    function template_chooser($template)
    {
    global $wp_query;
    $post_type = get_query_var(‘post_type’);
    if( $wp_query->is_search && $post_type == ‘member’ )
    {
    return locate_template(‘archive-member.php’);
    }
    return $template;
    }
    add_filter(‘template_include’, ‘template_chooser’);

  14. linx says

    i’ve created an archive-member.php and a search form to filter the results. however everytime my search includes the ‘s’ query string, it displays the results in the archive.php. eg:
    ?post_type=member&s=custom_post_title (displays results in archive.php)
    ?post_type=member&custom_taxonomy=developer (displays results in archive-member.php)

    i want all results that uses ?post_type=member to display in the archive-member.php.

    please help

  15. Davy says

    Thanks, this is really helping me out!

    But I don’t get it the way I want it to. If I look at the examples given at the end, it looks quite similar to what I want to establish.

    I want to show 3 posts per row, with each post the title and thumbnail. When clicking on them there will be a pop-up window. (Html is ready for it so I only need to know how to set this up)

    This archive page is pretty much the same as I displayed my post in each category, but I’m getting stuck here..

    So how do I get this in to the php correctly?

    The page I made before, didn’t showed the posts but an link to archive….

    Can you help me out and tell me how the example pages work?
    They are quite similar to what I want.

    Thanks already,

    Davy

  16. raul says

    Hi there,

    Very helpful article. I’ll be trying it soon.
    I have a related question:

    Would you be able to somehow display the list of custom post archive pages, including not just the title of the pages, as you have it:
    • opinion
    • showcase
    • themes

    …but displaying also a featured image for each archive page, the way you can with post lists?

    • WPBeginner Support says

      Yes sounds do able. One easier approach would be using featured images with the same name as custom post type then you can use something like:

      <?php
      
      $args = array(
         'public'   => true,
         '_builtin' => false
      );
      
      $output = 'names'; // names or objects, note names is the default
      $operator = 'and'; // 'and' or 'or'
      
      $post_types = get_post_types( $args, $output, $operator ); 
      
      foreach ( $post_types  as $post_type ) {
      
         echo '<img src="/path/to/images/' . $post_type . '.png" />';
      }
      
      ?>
      

      Needs improvement but we hope you get the idea.

      Administrateur

  17. Jamshed says

    Thanks a lot for this.

    It’s really helpful for me to understand the flow of custom post type and how to handle it!
    :)

    thanks again……

  18. Lorenzo says

    Hi,
    Thanks for this tutorials.

    Is possible to display, a Title and Description in a archive-post_type.php page?

    I have lot of archive page in my site and I want to set a good SEO for this page.

    I have create all Custom Post Type with a Custom post type UI plugin and with a Yoast plugin now I can set all SEO option in all custom post type but not in archive page.

    Have a suggest for me?
    Thank you
    Lorenzo

      • Lorenzo says

        Thank you!

        I know this opportunity but I meant :

        with the and code? how I can insert?

        and

        I have a network of blog for administrate multilanguage site (this site are not build by me, I had take this work of administration this site) and archive-post_type.php call a type of Custom Post Type that have the same name for EN site and DE site.

        If add the code inside the archive-post_type.php, the Title and the Description are only in one language and I can’t insert SEO for DE site.

        I know that my site is complicated and built bad but I can’t change this setting and I search a solution for insert SEO title, meta description and meta keyword in all languages that is made my site.

        You think that is impossible for my settings?

      • Shahriar says

        « Go to Settings » Permalinks. Then click save again. This should work then. »

        It’s not working though I tried the way as you said. But same problem like IFTY. 404 error. I am using 3.5

      • Unknown Agent says

        >Go to Settings » Permalinks. Then click save again. This should work then.

        Was also getting a 404 error and this solved it.

        Would never of fixed this other otherwise as such a massively illogical solution

        Thank you!

  19. jim lott says

    To make pagination work you need to call the paged variable into your posts calls.

    query_posts( ‘post_type=xxxxxxx&post_status=published&posts_per_page=10&paged= » . get_query_var(‘paged’) ′);

  20. phpadam says

    I can’t get this code to work. In fact, I spent hours with it. I’m not sure what global $query_string actually does, but the code will not work while that is in there. No posts display at all. It’s as though the query doesn’t return any results.

    If I replace this line: global $query_string; query_posts($query_string . « post_type=mentions&post_status=published&posts_per_page=10 »);

    with this line query_posts( ‘post_type=mentions&post_status=published&posts_per_page=2’);

    I get results, but the pagination code does not work. The link changes from previous results to next results, but the result list does not change. The same posts are displayed on every page

  21. katarsis20032002 says

    the code above don’t work for me

    the solution i was found there was in the codex

     »

    For example, to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

    global $query_string; query_posts( $query_string . ‘&order=ASC’ );

    When using query_posts() in this way, the quoted portion of the parameter must begin with an ampersand (&)…

     »

    the & is missing

    this is the original link

    http://codex.wordpress.org/Function_Reference/query_posts

  22. jmdocherty says

    +1 for « does anyone know how to get the ‘next’ and ‘previous’ links working ». Thanks for the great post though

  23. Mike says

    Thanks for the post, how ever — Your method was returning all products from all categories. I modified it to retrieve only the products in the current category.

    $thisCat = get_category(get_query_var(‘cat’),false);
    query_posts(« post_type=product&post_status=publish&posts_per_page=10&cat= ».$thisCat->cat_ID);

  24. sander says

    Hi ,
    thanks for the tip!
    although i didnt get it working, until i deleted the « $query_string . » from the query_posts string.

    why is it in there?

    thanks again

    • Ramsey Stoneburner says

      @sander

      THANK YOU! for posting this! I was following the above tutorial and have been wracking my brain for several hours trying to get it to work. I decided to check the comments in case someone found anything and I got it working thanks to your comment!

    • Stephan Deglow says

      same for me
      @sander thank you

      @wp-beginner: please edit the article and take out that damn $query_string thingy

  25. Ben Tremblay says

    This is a nice step.
    For what I need? Half step.

    I’d love to use this for, say, posts that are parents, and posts that are their children.
    Catch is that a parent’s child can also have children, so that child is both child and parent. And if I can give that one both, I still have to keep the relationship straight … they aren’t apples and oranges in a barrel.

    But thanks!

Laisser une réponse

Merci d'avoir choisi de laisser un commentaire. Veuillez garder à l'esprit que tous les commentaires sont modérés selon notre politique de commentaires, et votre adresse e-mail ne sera PAS publiée. Veuillez NE PAS utiliser de mots-clés dans le champ du nom. Ayons une conversation personnelle et significative.