دیجی اسکریپت

افزودن دسته بندی به پست تایپ های سفارشی وردپرس | دیجی اسکریپت

افزودن دسته بندی به پست تایپ های سفارشی وردپرس
[ad_1]

یکی از کاربران از ما سوال کردند که در پست تایپ نوشته ها قابلیت دسته بندی پست ها هست، یا مثلا در پست تایپ محصولات ووکامرس می توانیم محصولات را دسته بندی کنیم. آیا در پست تایپ های سفارشی هم قابلیت دسته بندی مطالب فراهم هست؟

 

در پاسخ این دوست عزیز باید گفت: بله اینجا دنیای وردپرس هست و در دنیای وردپرس هیچ کاری نشد نداره 🙂 تصمیم گرفتیم خدمت شما عزیزان توضیح بدیم که چطور دسته بندی ها را به پست تایپ های سفارشی وردپرس اضافه کنید. شما در ابتدا باید کد نویسی برای ایجاد پست تایپ سفارشی در وردپرس را در قالب سایتتان اضافه کرده باشید. حالا که اضافه شد باید کد زیر را به args پست تایپ اضافه کنید:

 

'taxonomies'  => array( 'category' ),

 

یعنی کد نهایی باید به شکل زیر باشد:

 

/*
* Creating a function to create our CPT
*/

function custom_post_type() {

// Set UI labels for Custom Post Type
	$labels = array(
		'name'                => _x( 'Movies', 'Post Type General Name', 'twentythirteen' ),
		'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentythirteen' ),
		'menu_name'           => __( 'Movies', 'twentythirteen' ),
		'parent_item_colon'   => __( 'Parent Movie', 'twentythirteen' ),
		'all_items'           => __( 'All Movies', 'twentythirteen' ),
		'view_item'           => __( 'View Movie', 'twentythirteen' ),
		'add_new_item'        => __( 'Add New Movie', 'twentythirteen' ),
		'add_new'             => __( 'Add New', 'twentythirteen' ),
		'edit_item'           => __( 'Edit Movie', 'twentythirteen' ),
		'update_item'         => __( 'Update Movie', 'twentythirteen' ),
		'search_items'        => __( 'Search Movie', 'twentythirteen' ),
		'not_found'           => __( 'Not Found', 'twentythirteen' ),
		'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
	);
	
// Set other options for Custom Post Type
	
	$args = array(
		'label'               => __( 'movies', 'twentythirteen' ),
		'description'         => __( 'Movie news and reviews', 'twentythirteen' ),
		'labels'              => $labels,
		// Features this CPT supports in Post Editor
		'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
		// You can associate this CPT with a taxonomy or custom taxonomy. 
		'taxonomies'          => array( 'genres' ),
		/* A hierarchical CPT is like Pages and can have
		* Parent and child items. A non-hierarchical CPT
		* is like Posts.
		*/	
		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'show_in_nav_menus'   => true,
		'show_in_admin_bar'   => true,
		'menu_position'       => 5,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		'capability_type'     => 'page',
'taxonomies' => array( 'category' ),
	);
<div style="clear:both; margin-top:1em; margin-bottom:1em;"><a href="https://username.com/install-child-theme/?utm_source=postcontent&utm_medium=display&utm_campaign=more" target="_self" class="ub341af0c004a2e70481d5a734f98c1cf"><style>.ub341af0c004a2e70481d5a734f98c1cf{padding:0px;margin:0;padding-top:1em !important;padding-bottom:1em !important;width:100%;display:block;font-weight:bold}.ub341af0c004a2e70481d5a734f98c1cf
.ctaText{color:#7B1FA2;border:2px
solid #7B1FA2;border-radius:3px;padding:3px
۱۰px}.ub341af0c004a2e70481d5a734f98c1cf
.postTitle{color:#333}</style><div style="padding-left:1em; padding-right:1em;"><span class="ctaText">در ادامه بخوانید</span>  <span class="postTitle">جلسه ۴۶: آموزش نصب چایلد تم وردپرس</span></div></a></div>	
	// Registering your Custom Post Type
	register_post_type( 'movies', $args );

}

/* Hook into the 'init' action so that the function
* Containing our post type registration is not 
* unnecessarily executed. 
*/

add_action( 'init', 'custom_post_type', 0 );

 

حالا دسته بندی به پست تایپ های شما اضافه شده. بدون دردسر و بدون هیچگونه مشکلی!

نوشته افزودن دسته بندی به پست تایپ های سفارشی وردپرس اولین بار در اسکریپت ها پدیدار شد.

[ad_2]

لینک منبع مطلب

برچسب ها

این مطلب بدون برچسب می باشد.

ارسال دیدگاه جدید

به نکات زیر توجه کنید

  • نظرات شما پس از بررسی و تایید نمایش داده می شود.
  • لطفا نظرات خود را فقط در مورد مطلب بالا ارسال کنید.