Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I exclude elements from search and category pages? 
 
highway7
Jr. Member
 
Total Posts:  7
Joined:  2010-02-26
 

Hi,

In my header, I have excluded some elements from the home page with the following code:

<?php if ($this->getIsHomePage()):?>
    <?php 
else:?>
      
<div id="logo">
        <
a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo">
          <
img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
        </
a>
      </
div>
    
<?php endif; ?>

This works fine, but what I now need is a function which finds other pages, like the search page or category page. I have tried using <?php if ($this->getIsCategoryPage()):?> and <?php if ($this->getIsSearchPage()):?> without success.

Does anybody know where I am going wrong or how to exclude header elements from certain pages?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

for advanced search page:

$request $this->getRequest();//or Mage::app()->getRequest();
if ($request->getModuleName() == 'catalogsearch' && $request->getControllerName() == 'advanced' && $request->getActionName() == 'index'){//or $request->getActionName() == 'result'; //for result page
//this is advanced search page
}
same goes for quick search result
$request $this->getRequest();//or Mage::app()->getRequest();
if ($request->getModuleName() == 'catalogsearch' && $request->getControllerName() == 'result'){
//this is quick search result page
}

For category page:

$request $this->getRequest();//or Mage::app()->getRequest();
if ($request->getModuleName() == 'catalog' && $request->getControllerName() == 'category' && $request->getActionName()=='view'){
//this is category view page.
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
highway7
Jr. Member
 
Total Posts:  7
Joined:  2010-02-26
 

Thanks very much mate - exactly what I was looking for.

Is there any online source - other than this forum - where I can get this sort of information? How to say “if on the product page” etc?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

I don’t know such an online resource.
For product page do this:

if ($request->getModuleName() == 'catalog' && $request->getControllerName() == 'product' && $request->getActionName() == 'view'){
//this is the product page
}

Now after giving you a few fishes let me teach you how to fish.
Go on the page that you want to check and put this :

<?php echo "<pre>"print_r($this->getRequest()); echo "</pre>";exit;//the exist is optional
You will see a weird looking object printed out.
Right near the end you will see something like this:
[_module:protected] => catalog compare this to $request->getModleName();
 
[_moduleKey:protected] => module not important
 [_controller
:protected] => product compare this to $request->getControllerName();
 
[_controllerKey:protected] => controller not important
 [_action
:protected] => view compare this to $request->getActionName()
[_actionKey:protected] => action not important

Like this you can find out all the pages.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mirasvit
Guru
 
Avatar
Total Posts:  639
Joined:  2009-08-22
 

Check out these extension . They greatly improve the quality and relevance of search results Sphinx Search Ultimate http://mirasvit.com/magento-extensions/sphinx-search-ultimate.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kaushik Patel
Jr. Member
 
Total Posts:  28
Joined:  2011-12-24
 

try this.....
http://hkpatel201.blogspot.in/2013/03/magento-how-to-get-controller-module.html

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top