Creating custom post types (CPTs) is an essential skill for WordPress developers. ACF (Advanced Custom Fields) is a popular plugin, but it’s not always necessary. আজকের পোস্টে, আমরা ACF ছাড়া কিভাবে Custom Post Type তৈরি করবেন তা সহজভাবে ব্যাখ্যা করব। Let’s dive into the step-by-step process!
Why Custom Post Types?
Custom post types allow you to organize and display specific types of content beyond just posts and pages. উদাহরণস্বরূপ, যদি আপনার সাইটে একটি ‘Portfolio’ সেকশন দরকার হয়, তবে সেটি Custom Post Type দিয়ে সহজে তৈরি করা যায়।
Step 1: Add Code to functions.php
The first step is to register your custom post type in your theme’s functions.php file. নিচের কোডটি ব্যবহার করুন:
function create_portfolio_cpt() {
$labels = array(
‘name’ => (‘Portfolios’, ‘textdomain’), ‘singular_name’ => (‘Portfolio’, ‘textdomain’),
‘menu_name’ => (‘Portfolios’, ‘textdomain’), ‘name_admin_bar’ => (‘Portfolio’, ‘textdomain’),
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
'rewrite' => array('slug' => 'portfolio'),
'show_in_rest' => true, // For Gutenberg support
);
register_post_type('portfolio', $args);
}
add_action(‘init’, ‘create_portfolio_cpt’);

এই কোডটি functions.php ফাইলে যোগ করার পর, আপনি একটি নতুন Custom Post Type দেখতে পাবেন ড্যাশবোর্ডে।
Step 2: Customize Labels and Features
Above code e, supports array উল্লেখ করে কী কী ফিচার ব্যবহার করবেন। For example:
- Title: পোস্টের শিরোনাম।
- Editor: কন্টেন্ট এডিটর।
- Thumbnail: Featured image।
- Custom Fields: মেটাডাটা যোগ করার জন্য।
আপনার প্রয়োজন অনুযায়ী এই লেবেলগুলো কাস্টমাইজ করুন।
Step 3: Display Custom Post Type Content
To show your CPT content on the frontend, আপনি একটি নতুন template file তৈরি করতে পারেন:
- Create a file named
single-portfolio.phpin your theme folder. - Use the following code to fetch the data:
<?php get_header(); ?>
<div class=”portfolio-content”>
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<div><?php the_content(); ?></div>
<?php endwhile;
endif;
?>
</div>
<?php get_footer(); ?>

Bonus: Use Custom Taxonomies
Custom Post Type-এর সাথে Custom Taxonomies (e.g., Categories বা Tags) যোগ করতে পারেন। কোডটি এমন হবে:
function create_portfolio_taxonomy() {
register_taxonomy(
‘portfolio_category’,
‘portfolio’,
array(
‘label’ => __(‘Categories’, ‘textdomain’),
‘rewrite’ => array(‘slug’ => ‘portfolio-category’),
‘hierarchical’ => true,
)
);
}
add_action(‘init’, ‘create_portfolio_taxonomy’);

Final Thoughts
ACF ছাড়া Custom Post Type তৈরি করা একটু বেশি কাস্টমাইজেশন দেয়। কোড ব্যবহার করলে আপনি আপনার সাইটে অতিরিক্ত প্লাগিন ব্যবহার না করেও কাজ চালিয়ে যেতে পারবেন। আশা করি, এই টিউটোরিয়ালটি আপনাদের কাজে লাগবে।
যদি আপনার কোনো প্রশ্ন থাকে, comment করে জানান!
Happy coding! 😊