WordPress Beginner’s Guide to Get Category Information in category.php – WordPress Tutorial

By | August 12, 2019

WordPress category.php is used to display posts or pages in one category. In this tutorial, we will introduce how to get category object in category.php, then you can customize it to display.

wordpress cateory information

Open category.php

Add code below in this page.

<?php $cat = get_category(get_query_var('cat')); ?>

Print $cat.

<?php print_r($cat);?>

The output may be:

stdClass Object
(
[term_id] => 85
[name] => Category Name
[slug] => category-name
[term_group] => 0
[term_taxonomy_id] => 85
[taxonomy] => category
[description] => 
[parent] => 70
[count] => 0
[cat_ID] => 85
[category_count] => 0
[category_description] => 
[cat_name] => Category Name
[category_nicename] => category-name
[category_parent] => 70
)

From the result, you can get cat_name, cat_ID, category_description etc al. Then you can display these information at anywhere of page.

Leave a Reply