2013-10-24 06:29
浏览 17


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

图片转代码服务由CSDN问答提供 功能建议

如果当前页面是类别页面,我必须插入一些条件。 < / DIV>

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongzhuang6417 2013-10-24 06:29

    I have found the way to do it by checking if $cat_id is available or not 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.

    打赏 评论
  • duanji2002 2013-10-24 06:35

    You can use




    打赏 评论
  • douhao8456 2013-10-24 07:05

    you can use this for getting 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
    打赏 评论
  • douchao1957 2017-08-08 13:52

    Amit's answer will work but there is a simpler way as Wordpress sets a Global var for the category id of $cat. So just checking if this is set will tell you if you are on a category page.

    if(!empty($cat)){ //do something just on a category archive page }
    打赏 评论

相关推荐 更多相似问题