Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if current page is category page in wordpress?

Tags:

php

wordpress

I have to insert some condition if the current page is a category page or not.

like image 725
Amit Garg Avatar asked Oct 24 '13 06:10

Amit Garg


People also ask

How can I get current page category in WordPress?

$category = single_term_title("", false); $catid = get_cat_ID( $category );

How do I view WordPress categories?

You can also view your WordPress category ID by editing it. Simply open a category to edit, and you'll see the category ID in the browser's address bar.

How do you check a WordPress page?

So, what you need to do is add '/wp-admin/' at the end of the domain (homepage URL) of the website. If it redirects to the login page, then you can determine that the website uses WordPress. For example, if your website URL is 'https://example.com', then add '/wp-admin/' at the end of it.


2 Answers

you can use this for getting category

is_category();
is_category( '1' ); // where 1 is category id
is_category( 'test' ); // where test is category name
is_category( 'test-ing' ); // where test-ing is category slug
like image 165
Jigar Patel Avatar answered Oct 14 '22 21:10

Jigar Patel


I have found the way to do it by checking if $cat_id is available or not on that page by the following.

$cat_id = get_query_var('cat');

Now we can check if $cat_id is available then it is a category page otherwise it is not.

like image 41
Amit Garg Avatar answered Oct 14 '22 22:10

Amit Garg