0

I have an page url of magento site.

my question is : how can i check the page url is category page or cms page or other page?

for example:

page URL is : http://example.com/craft.html(category page) or http://example.com/terms-policy(cms page)

i want to check page url is category page or cms page.

Thanks.

  • $this->getRequest()->getControllerName() == 'cms' is CMS page – Minesh Patel Dec 16 '17 at 12:05
  • blog.chapagain.com.np/… – Minesh Patel Dec 16 '17 at 12:06
  • 1
    hi @MineshPatel no i don't want this. your code match current page controller name with "cms". i edit my question with an example please see. – pooja Dec 16 '17 at 12:12
  • You need to check in Table core_url_rewrite and cms_page for this – Minesh Patel Dec 16 '17 at 12:58
0

I think the answer given by Minesh in comments are partially correct. If you are trying to check it in your template file you can use below codes to check whether you are in category page, cms page or product page.

To check if you are in category page:

if (Mage::registry('current_category'))
{
  // category page
}

To check if it is a cms page:

if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
  // CMS page
}

To check if it is a product page:

if(Mage::registry('current_product'))
{
  // Product detail page
}

Edited

From your comment, below code will let you know the last page url is either cms page, or category or product.

$lastUrl = Mage::getSingleton('core/session')->getLastUrl();
    if (preg_match("#cms/index/index#", $lastUrl)) {
        return "Last page was:<br>Home page<br/>url: ".$lastUrl;
    }
    elseif(preg_match("#catalog/category/view#", $lastUrl)) {
        return "Last page was:<br>Category page<br/>url: ".$lastUrl;
    }
    elseif (preg_match("#catalog/product/view#", $lastUrl)) {
        return "Last page was:<br>Product detail page<br/>url: ".$lastUrl;
    }
    else
    {
        return "Last page was:<br>Unknown page<br/>url: ".$lastUrl;
    }

I hope this will help. If it works for you pleae don't forget to accept and vote the answer. This will help others too.

Happy Coding!!

  • 1
    your answer is correct @aton1004 but i need to get the page type on another page. for example: if i am on category page and its previous page is home page then i need to show home page type (cms) show on category page. inshort, i need to know the previous page type. is it cms or category. – pooja Dec 18 '17 at 7:00
  • @pooja from your question it was not clear of your requirement. Please check the code from edited section to find your answer. if it helps don't forget to accept and vote up the answer. Cheers!! – aton1004 Dec 18 '17 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.