douji6667
2013-10-24 06:29
浏览 17
已采纳

检查当前页面是否是wordpress中的类别页面?

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

    is_category();
    

    function.

    refrence: http://codex.wordpress.org/Function_Reference/is_category

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

    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
    
    打赏 评论
  • 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 }
    
    打赏 评论

相关推荐 更多相似问题