Custom type posts – creating a list with custom post type in WordPress
In this article you will learn how to create a list with custom post in WordPress. If we have a set of entries of a given type and would like to create a list view that displays all the posts, we need to create a file that would handle it. In our case we will be based on a previously created article Advanced Custom Fields – custom field types WordPress, where we added our own type of entries: Projekt. On the basis of these projects we would like to create a list of projects, which would properly display: The title of the project, a short description of the project, a distinguishing image.
How do you create a list with custom post type of entries in WordPress ?
Let’s do it
The first step is to edit our Custom Post Type Project. Let’s go to CPT UI tab in WordPress panel. Let’s choose our Post Type Design and look for the Has Archive section. Let’s change the value to true and set the url – ”projekty”.
After approving the change in our post type Projekt, let’s go to the folder of our theme – in our case wp_tutorial and find the archive.php file. This file is responsible for displaying a set of basic WordPress entries. To create a list view of your own type of entries, follow the same procedure as in Create a view (template) for a custom post in WordPress. Copy the archive.php file and add Custom Post Type Slug: archive-projekt.php.
.
We are going to edit the archive-projekt.php file. By default, the code and view are as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php get_header( |