I'm trying to pre-select the current category in the header search bar in Magento 1.9.2.1. This would allow users who search for an 'item a' in 'category a' to then be able to perform a follow up search for an 'item b' also scoped to 'category a'.
I've tried the following in the search bar .phtml, but nothing appears to be set when viewing a category or product page.
$cat = Mage::registry('current_category');
$prod = Mage::registry('current_product');
$cat = Mage::getModel('catalog/layer')->getCurrentCategory();
$cat = $this->getCurrentCategory();
$cat = $this->getLayout()->getBlock('product_list')->getCategoryId();
Whats the proper way of getting the category id in a header template? Thanks!