Do you want better
IT Services ?

Let our experts help you navigate the digital world with tailor-made IT Solutions!

Table of Contents

Taxonomy is a way to group things together. In WordPress we have three taxonomies Category , Tags and Link Categories. If we are writing custom post types we need to add a custom taxonomies to associate with them. Recently I wrote an article with downloadable snippet on how to create a custom post type, so if you don’t know what custom post types are, just go through Custom Post type tutorial first. Now lets move on to custom taxonomies creation with register_taxonomy(); function.

You can add this code into your functions.php file and it will generate a custom taxonomy (like categories in posts) and add custom taxonomy to portfolio and post.

<?php
if ( ! function_exists( 'portfolio_taxonomy' ) ) {

// Register Custom Taxonomy
function portfolio_taxonomy() {

	$labels = array(
		'name'                       => _x( 'Portfolio Categories', 'Taxonomy General Name', 'text_domain' ),
		'singular_name'              => _x( 'Portfolio Category', 'Taxonomy Singular Name', 'text_domain' ),
		'menu_name'                  => __( 'Category', 'text_domain' ),
		'all_items'                  => __( 'All Items', 'text_domain' ),
		'parent_item'                => __( 'Parent Item', 'text_domain' ),
		'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
		'new_item_name'              => __( 'New Item Name', 'text_domain' ),
		'add_new_item'               => __( 'Add New Item', 'text_domain' ),
		'edit_item'                  => __( 'Edit Item', 'text_domain' ),
		'update_item'                => __( 'Update Item', 'text_domain' ),
		'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
		'search_items'               => __( 'Search Items', 'text_domain' ),
		'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
		'choose_from_most_used'      => __( 'Choose from the most used items', 'text_domain' ),
		'not_found'                  => __( 'Not Found', 'text_domain' ),
	);
	$args = array(
		'labels'                     => $labels,
		'hierarchical'               => true,
// Is this taxonomy hierarchical (have descendants) like categories or not hierarchical like tags.
		'public'                     => true,
		'show_ui'                    => true,
		'show_admin_column'          => true,
		'show_in_nav_menus'          => true,
		'show_tagcloud'              => true,
	);
	register_taxonomy( 'portfoliocategory', array( 'post', ' portfolio' ), $args );
// this taxonomy will be added to post and portfolio post type. If you want to add this taxonomy to more post types, simple add them to above array separated with a coma.

}

// Hook into the 'init' action
add_action( 'init', 'portfolio_taxonomy', 0 );

}
?>

Calling Custom category on portfolio Single Page with get_the_term_list function

<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>

Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.

<?php 
$pcategory_list = get_the_term_list( $post->ID, 'portfolio_category', '<strong>Portfolio Categories :</strong> ', ', ', '' ); ?>

<?php echo $pcategory_list; ?>	

WordPress vs A Custom based php Website

WordPress and a custom PHP website are two different approaches to building a website. Here are some differences between the two: Ease of use: WordPress is generally easier to use than a custom PHP website, because it has a user-friendly interface and a large number of plugins and themes that allow you to easily add...

Read More

10 ways to bring targeted audience to your website

Search engine optimization (SEO): Optimizing your website for search engines can help bring targeted traffic from people searching for keywords related to your business. Pay-per-click (PPC) advertising: PPC advertising platforms like Google AdWords allow you to create ads that appear at the top of search engine results pages when people search for specific keywords. Content...

Read More

Top 8 Benefits of Having a Website

Top 8 Benefits of Having a Website Whether you’re a small business or a large corporation, having a website is essential to your success. In today’s digital world, people are used to getting their information online, and if you don’t have a website, you’re missing out on a huge opportunity. A website allows you to...

Read More

What is web hosting and why do I need it ?

Unless you are planning to build a website from scratch, you will need web hosting. Web hosting is a service that provides you with the technology and resources necessary to build and maintain a website. Think of it this way: if a website is like a house, then web hosting is like the land it’s...

Read More

How To Find The Right Website Designer For Your Business

A website is the face of your business – so it’s important that you take the time to find a designer who will create something that accurately represents your company. In this blog post, we’ll explore the process of selecting a designer, what you should keep in mind when hiring one, and how to go...

Read More

A Guide To Why You Need A Dynamic Website

The world has changed. The way people search for things have changed. The way they use technology to do their work have changed. Gone are the days when you create a website and take it as it is, customers will want more information, they’ll want better content, so you need to be ready to provide...

Read More
Scroll to Top
Scroll to Top

We help businesses with Websites, Mobile Applications, Digital Marketing, E Commerce Solutions & Custom Software.