How to Get Category Name by Category ID in WordPress

Add Tool

Get Category Name by Category ID in WordPress


Get Category Name by Category ID in WordPress

If you want to create a newspaper site or blog site like newspaper you need to display post base on category. Here I have added a WordPress Snippets which will display category name by Category ID.

<?php echo get_cat_name(4);?>

Here get_cat_name(4) is my Selected Category ID. Please Change 4 With you Category ID.

Category link with Category ID

The above WordPress snippets will display only Category name. If you want to add link of the category you need to add below snippets.

<?php echo get_category_link(4); ?>

Here get_category_link(4) will display category link by Category ID. Please Change 4 With you Category ID.

Category name with category link by ID

The above two snippets will display Category name and category link separately by category id. I only added the above two codes as a link.

<a href="<?php echo get_category_link(4); ?>"><?php echo get_cat_name(4);?></a>

A small project of above snippets

Simply add the below WordPress snippets where you want to display post from specific category. If your sidebar widgets support php code, You can add it into you sidebar using text widgets.

<h2><a href="<?php echo get_category_link(4); ?>"><?php echo get_cat_name(4);?></a></h2>
<ul>
  <?php
	$catquery = new WP_Query( 'cat=4&posts_per_page=10' );
	while($catquery->have_posts()) : $catquery->the_post();
	?>
  <li> 
    <a href="<?php the_permalink() ?>" rel="bookmark">
     <?php the_title(); ?>
    </a>
  </li>
  <?php endwhile; ?>
</ul>

The above code will display 10 post for you category. You need change category ID.

If you have any question or problem about the snippets. Don't forget to ask me using comment section. If this post is helpful don't forget to share.


Tags: category name by id, category name by id in WordPress, wp get category name by id, get category id by name, WordPress get posts by category name, WordPress current category name
Payza

About Masum Billah

Get Category Name by Category ID in WordPress 1stWebSuite website seo tool is a free website ranking tool site provides a lot of on page and off page seo useful tools for you. On this site, we have a large number of website ranking tools


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: How to Get Category Name by Category ID in WordPress


adf.ly