Pretty stuck !
I made a custom post type for my WP back office :
register_post_type('realisations',[
'label' => 'Réalisations',
'public' => true,
'menu_position' => 3,
'menu_icon' => 'dashicons-format-gallery',
'supports' => ['title', 'editor', 'thumbnail'],
]);
and I want all the articles to display in my custom template :
<?php/* Template Name: Réalisations */?>
<?php materialis_get_header();?>
<div class="top-page">
<div class="title">
<i class="fas fa-camera"></i>
<h2>Réalisations</h2>
</div>
<div class="description-page">
<p>Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen</p>
</div>
<div>
</div>
</div>
<?php get_footer(); ?>
So I tried this old code that I found and it’s only showing the title of the post , not the articles inside :
<?php/* Template Name: Réalisations */?>
<?php materialis_get_header();?>
<div class="top-page">
<div class="title">
<i class="fas fa-camera"></i>
<h2>Réalisations</h2>
</div>
<div class="description-page">
<p>Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen</p>
</div>
<div>
<?php
$custom_post_types = get_post_types(
array(
// Set to FALSE to return only custom post types
'_builtin' => false,
// Set to TRUE to return only public post types
'public' => true
),
// Set to "objects", so we have the full CPT object
'objects'
);
// Add CPT permalinks to CPT objects
foreach ( $custom_post_types as $custom_post_type ) {
$custom_post_type->permalink = get_post_type_archive_link( $custom_post_type->name );
}
// Output CPT archive index permalinks list
echo '<ul>';
foreach ( $custom_post_types as $custom_post_type ) {
echo '<li>';
echo '<a href="' . $custom_post_type->permalink . '">' . $custom_post_type->name . '</a>';
echo '</li>';
}
echo '</ul>';
?>
</div>
</div>
<?php get_footer(); ?>
Sorry for being a nooby in wordpress ! And thanks for your upcoming answers !
2
Answers
so – a little mix-up. This code (Example ahead) is used to create a custom post type in WordPress… its similar to a normal post (like the one used in the blog) and not a page template which you tried to apply.
There are a few differences between ‘custom post types’ and ‘page templates’. Page templates are still pages which mean they have no categories, usually no featured image (thumbnail) and are not queried in chronological order (by default) and also in the way we define them for use in the theme.
Custom post type are very similar to posts – you could create "categories" structure for them, add tags etc.
This is how you setup a custom post type
In your theme functions.php or file included into it.
To use these you need to create a file named
The name is structured like this: single-CUSTOM_POSTYPE_NAME.php
create that file in the root folder of your theme. then you could visit the new postype you created – if you encounter any problem visit the permalinks page (in wp backend) – a visit would refresh the permalink structure.
example code for single-project.php
This is all very basic – I encourage you to use youtube in order to learn more about custom postype because it is hard to explain this in a short answer without sharing a screen.
Best of luck..
Create .php file and add this code and select your template Réalisations form your admin panel