简体   繁体   中英

Magento: How can i do a if product page then, else if category page then, else if cms page then

I have a challenge doing the following statement. In breadcrumbs.phtml I would like to do the following:

h1
if cms page then getTitle
else if category page then getName
else if product page then getName
/h1

Now I figured out these two statements:

<?php echo Mage::registry('current_product')->getName()?>
<?php echo Mage::registry('current_category')->getName()?>

but I can't figure out how to get them into the if statement or how to make the if statement entirely.

Any help is much appreciated.

I tried the above advice:

<?php
if($this->getRequest()->getModuleName() == 'cms') {
echo Mage::getSingleton('cms/page')->getTitle();
} else if($this->getProductPage()) {
echo $this->getLayout()->getBlock('head')->getTitle();
} else if ($this->getCategoryPage()) {
echo Mage::registry('current_category')->getName()
}
?>

But it didn't work.

can you see whats wrong?

if($this->getRequest()->getModuleName() == 'cms') {
    // it will return 'cms' string
} else if($this->getProductPage()) {
  // this will check if you are in product page
} else if ($this->getCategoryPage()) {
  // this will check if you are in category page
}

getProductPage deprecated getCategoryPage deprecated

instead of above code, please try this and let me know result :

if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'):
    $Page = Mage::getSingleton('cms/page')->getTitle(); 
endif;   

if($Page == 'catalog'):
    $Page->getName();
endif;

if($product = Mage::registry('current_product')):
   $product->getName();
endif;

if($catalog = Mage::app()->getRequest()->getControllerName() == 'category'))):
   $catalog->getName();
endif;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM