Magento: How to tell if you're on a category page, or product page in .phtml file(s)

前端 未结 4 779
余生分开走
余生分开走 2021-02-02 11:57

I am trying to program into my .phtml files an if statement if the guest is on a category list page, or on a product page.

For example this code:



        
4条回答
  •  忘了有多久
    2021-02-02 12:12

    I am not a big fan of checking if the current_category registry exists, because basically any controller could do this and it wouldn't necessarily mean it's a category. My way of doing it is a bit more robust:

    $fullActionName = Mage::app()->getFrontController()->getAction()->getFullActionName();
    if ($fullActionName == 'catalog_category_view') { 
        ...  //Category
    }
    elseif ($fullActionName == 'catalog_product_view') {
        ...  //Product
    }
    

提交回复
热议问题