how to display categories for a specific post?

for example : I have a Post Name computer and electronics and this post consist of two category 1.LED displays 2.Mobiles , now i want to display post = computer and electronics with it's specific categories.

Topic categories Wordpress

Category Web


for that purpose you need to use get_the_category($id) function, which accept the post id as parameter and return a list of terms object assigned to the passed post id, you can refer to this url to learn more.

https://developer.wordpress.org/reference/functions/get_the_category/


You can use single_cat_title function to get category's name.

Useful for category template files for displaying the category page title. The prefix does not automatically place a space between the prefix, so if there should be a space, the parameter value will need to have it at the end.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.