Enable Custom Post Types in the Theme:
Step 1: In your WordPress theme's functions.php file, add the following code to enable custom post types:
function custom_theme_setup() {
register_post_type('industry', array(
'labels' => array(
'name' => 'Industries',
'singular_name' => 'Industry',
),
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail'),
));
}
add_action('after_setup_theme', 'custom_theme_setup');
Create a New Industry:
Step 2: In your wordpres dashboard , You will see newly created custom post typ like below I have created industry custom post type.
- Go to the WordPress dashboard.
- Navigate to "Industries" > "Add New."
- Enter the details of the industry, such as the name and any additional information in the editor.
- Click the "Publish" button to save the industry.
Display the Industry on a Page:
To display the industry details on a specific page, you can create a custom page template:
- Create a new file in your theme's directory and name it "page-industry.php."
- Add the Code to Display Industry Details:
- Inside the "page-industry.php" file, add the following code to display the industry details:
'industry',
'posts_per_page' => -1, // -1 will display all posts of the custom post type
);
$industry_query = new WP_Query($args);
// The Loop
if ($industry_query->have_posts()) {
while ($industry_query->have_posts()) {
$industry_query->the_post();
?>
No industries found.';
}
/* Restore original Post Data */
wp_reset_postdata();
?>
Error message of 404 error:
If you get an error of 404 error page. Ensure that your WordPress permalinks are set up correctly. Go to "Settings" > "Permalinks" in the WordPress dashboard and select the "Post name" option or any other desired permalink structure. Click the "Save Changes" button to update the settings. Sometimes, simply resaving the permalinks can fix the 404 error.