Hello,
I'm currently searching how to noindex a product list page when there is for example, less than 3 products shown, in order to improve SEO.
Could you please give me any advice to realize it ?
Thank you for your assistance, have a nice day.
I think the best way is to observer the event controller_action_layout_generate_blocks_after
<events>
<controller_action_layout_generate_blocks_after>
<observers>
<controller_action_layout_generate_blocks_after>
<class>Namespace_Company_Model_Observer</class>
<method>setRobotsTag</method>
</controller_action_layout_generate_blocks_after>
</observers>
</controller_action_layout_generate_blocks_after>
</event>
and set the robots tag like this:
public function setRobotsTag($observer)
{
$controller = $observer->getAction();
$action = $controller->getFullActionName();
if ($action == 'catalog_category_view') {
$category = Mage::registry('current_category');
if ($category && $category->getProductCount() < 3) {
$observer->getLayout()->getBlock('head')->setRobots('NOINDEX,FOLLOW');
}
}
}