How to print the parent category id or slug using subcategory id or slug in osclass

0

I have googled many times for printing parent category “id” or “slug” using subcategoy “id” or “slug” in osclass for some listing functionality.

In osclass site there is no predefined function to print the parent category “id” or “slug” using subcategory “id” or “slug”. So i have created one function to print the parent category “id” or “slug” using its subcategory “id” or “slug”.

The function can be added into the functions.php file inside the theme folder. In osclass site we can use custom functions but it should not bother the default functions.

I have given some explainations with the coding and how to use the function to print the parent category “id” or “slug” using subcategoy “id” or “slug”.

Paste the function at the bottom of the function.php file inside the theme folder. Be sure not to leave any space after the function.

This is the function which accepts only parent id as parameter.so you have to pass the category id as parameter for the given below function when calling the function.

This is the function which accepts only parent slug as parameter.so you have to pass the category slug as parameter for the given below function when calling the function.

Call the function anywhere in the theme files and pass the category id as parameter for the function .  you will get a result array which has the details for slugname, parent category id ect… Function calling example using category id as parameter,

Function calling example using category slug as parameter,

you can print the result array using print_r($values) for your understanding. If the parameter your passing to the function is the parent category , then the result array only print its category name, slug, category id in the result array. If the parameter your passing to the function is subcategory , then you will get the category and its parent category details.

Share.

About Author

I have no more personal information to share with you but have enough experience to share with all. I am always funny