Being a WordPress-based theme, Divi offers many unique benefits to its users. You can have outstanding design, plus the capability to improve it using the Divi Theme Builder. Furthermore, you can have Divi custom post types utilized through the Builder.
Now, if you don’t have any custom post type in Divi and want to create one, for whatever reason, then I’ll guide you on how to do that in this post. But before that, let’s cover what’s a custom post type.
So, you’d be sure that it’s what you need, not the taxonomies.
What’s a Custom Post Type?
WordPress and custom post types (CPTs) go as one. Through custom post types in WordPress, you can add and display various types of formats on the website. By default, you get multiple post types, such as Posts and Pages.
Through Posts, you can maintain your blog and publish something that you want to update on a regular basis. For example, through blogs, you can build a readership that might help you in your business or career.
On the other hand, pages let you add information that is generally useful to help users learn about the business or professional services you provide.
Now, what’s important to notice here is that Posts and Custom Post Types aren’t the same. A CPT is a collection of a particular content format, whereas posts are the format. Hence, you find multiple CPTs in WordPress in addition to Posts or Pages, such as
- Attachments
- Revision
- Navigation Menus
- Products – A new custom post type is added to the website when installing the WooCommerce plugin.
How Custom Post Type Can Help?
Well, custom post types are beneficial in WordPress. They let you implement additional content formats that make processing specific data for the situation manageable. For instance, you want to process data on bookings. By default, you don’t get any CPT that would let you do that.
However, creating a custom post type allows you to efficiently process bookings for check-in and check-out, type, price and more. The overall reason for using a custom post type in WordPress is to add more room to the site in addition to posts, pages and other content formats.
How to Create Custom Post Type in Divi
Now, come to Divi custom post type. Well, CPTs associated with Divi are just the same as WordPress. And the following methods we will follow allow you to create custom post types in Divi with no extra effort.
While you create a Divi custom post type, why you need that post type and not another is important. Let’s get to our method.
Creating Divi Custom Post Type Using Code
To keep things under our control entirely, the best way to create custom post types is through code. The code helps us keep the platform light, plus we don’t have to perform various actions. However, using plugins is best when they offer the most accessible, highly useful options.
So, to create a custom post type in Divi using code, first, ensure you have access to the website’s server using an FTP client or cPanel. And you’re using a child theme. It’s highly recommended you use a child theme.
If you match the above situation, then first go to Appearance → Theme File Editor.
Once the file editor is opened, select the theme presently activated, then select the functions.php file. You can also do the same in the FTP client.
Now, you’ll see the code of your functions.php file. Inside the file, paste the following code which will create a custom post type for Book Reviews.
// Creates Book Reviews Custom Post Type
function book_reviews_init() {
$args = array(
'label' => 'Book Reviews',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'book-reviews'),
'query_var' => true,
'menu_icon' => 'dashicons-book-alt',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',)
);
register_post_type( 'book-reviews', $args );
}
add_action( 'init', 'book_reviews_init' );
If you want to create the custom post type for something else, you can change the “book” labels. Now, after pasting the code, update your file and refresh. You’ll see a new menu option in the dashboard, like the screenshot below.
You might be thinking that your job is done, but no, we’re not done yet. To display the content of your custom post type, you need to create a custom post template. So, to do that, access your website’s server (in this case, you need to access the website’s file through an FTP client or cPanel.)
Once the files are accessed, go to your theme folder and upload/create a new file, page-book-reviews.php. In it, paste the following code to help WordPress consider it as a new template.
/**
* Template Name: Book Reviews
**/
If you don’t create this file, your custom post type will enter the 404 page not found error. Hence, create the file and then go to the page.php file, copy its entire code, and paste it into the above new template file you created.
The new template file with the above code will look like the following.
We copied the code to keep our custom post type design similar to the page we have. Once you have pasted the code, look for the following code:
<?php while ( have_posts() ) : the_post(); ?>
// Your code
<?php endif; ?>
<?php endwhile; ?>
And replace it with the following,
<?php
$query = new WP_Query( array('post_type' => 'book-reviews', 'posts_per_page' => 5 ) );
while ( $query->have_posts() ) : $query->the_post(); ?>
// Your code e.g. "the_content();"
<?php endif; wp_reset_postdata(); ?>
<?php endwhile; ?>
Once done, save your new template file. And it will start to display the content once you publish your custom post type posts.
Quick Solutions for Custom Post Types
Custom post types help add additional content other than pages or posts. The above solution is good when you’re looking to add a primary custom post type. However, you should check out the following when the requirement is advanced.
Divi Blog Extras (Divi Plugin to Display CPT in different layouts including slider and masonry grid).
Divi Blog Extras is a premium plugin for Divi that allows you to customize archive pages. It provides you with 8 beautiful layouts that can help you build unique blog pages. In addition, it supports custom post types. So, if you’ve already added a custom post type and want to present the information more creatively, you can try this plugin.
Divi Testimonial Extended (Plugin for Divi that adds a CPT for Testimonials and display them on front end using module).
Customer reviews are the easiest way to gain trust in the minds of new users. If you plan to create a custom post type for reviews/testimonials in Divi, then Divi Testimonial Extended will be perfect for your use. It provides you with multiple testimonial layouts, including the slider. Plus, it also adds a custom post type for testimonials so you can easily manage your customers’ reviews.
Divi Restro Menu (Divi restaurant plugin with CPT).
For restaurant websites, food menus and categories are a crucial part. Without them, a restaurant’s website is incomplete. Therefore, the Restro Menu plugin by Divi Extended brings the tools to make a food website highly functional. If you’re looking to add a custom post type for recipes, then using this plugin it’s possible. It adds a custom post type for Food Items and Categories.
In summary, leveraging custom post types in Divi extends your website’s capabilities, allowing for unique content organization and display. Through code or specialized plugins, you can tailor your site to specific needs, from showcasing book reviews to managing restaurant menus, enhancing both functionality and user engagement.
0 Comments