WordPress Tutorial

WordPress Method for Adding Custom Column Fields to Classifications

 Alibaba Cloud

At present, WordPress is very convenient for domestic use, but in general, if we want to add additional attributes to articles in the WordPress system, we usually think of using custom columns (also called custom fields), which also greatly enhances the extensibility of WordPress. For example, I want to use WordPress to create an online sales website, Then each commodity has attributes such as price, color and weight. At this time, I can use user-defined columns to record this part of data. A netizen left a message to me, saying that since articles can add custom fields, can WordPress add fixed fields to categories? The category directory only includes name, alias, parent and description. For example, if I have a movie category, I can't add another thumbnail or category keyword of the movie category. This article solves this problem.

Category Meta plugin, It is powerful and can be used to add custom columns to categories, labels, custom menus, link categories, etc. It supports single line/multi line text boxes, multi selection boxes, and image uploading.

Want to be here? contact us bar
 Maker host

usage method

After activating the plug-in, go to the background - Settings - Category Meta, where you can create/manage the custom columns you add.

Meta Name: the name of the added user-defined column (in English);
Sanitize meta name: generally checked;
Meta Type: select the type of user-defined column, including Text single line text box, Text Area multi line text box, Image image upload, and Check Box multi selection box
Meta Topology: where to add custom columns, you can select category classification, post_tag tag, nav_menu menu, link_category link tag, post_format

Finally, click Add Meta to add the desired custom columns. For example, if our Meta taxonomy selects category, you can see the custom column color just added in the article category directory.

How to call the value of this custom column? You can use the following php code:

  1.  if  ( function_exists ( 'get_terms_meta' ) )  {
  2.    //$category_id is the category id, and $meta_key is the user-defined column name (that is, the Meta Name you filled in above)
  3.    $metaValue  = get_terms_meta ( $category_id ,  $meta_key ) ;
  4.    echo  $metaValue [ zero ] ;
  5.  }

For example, under the theme directory, the template used by the general category directory is category.php or this is archive.php. Then we can add code to these php files:

  1.  if  ( is_category ( )  )  {
  2. 	 if  ( function_exists ( 'get_terms_meta' ) )  {
  3. 		 //Get_query_var ('cat ') is the current classification ID, and color is the user-defined column name I use (that is, the Meta Name filled in above)
  4. 		 $metaValue  = get_terms_meta ( get_query_var ( 'cat' ) ,  'color' ) ;
  5. 		 echo  $metaValue [ zero ] ;
  6. 	 }
  7.  }

WordPress Method for Adding Custom Column Fields to Classifications

328 people have bought
View Demo Upgrade VIP Buy Now

Collection
fabulous ( zero )

Post reply

Hot selling template

Ashade - Works exhibition photo album WordPress Chinese theme
 LensNews

This site accepts WordPress/PbootCMS/DedeCMS, etc
System construction, imitation, development, customization and other services!