Search code examples
phpjoomlaquery-stringrequest-uri

Show joomla modules only on specific URL using PHP condition with Metamod


I need to show modules only on pages which url contains "saucony". For example show product slider only on pages like: /sneakers/woman-sneakers-saucony-dxn-trainer-black-orange-detail or /sneakers/woman-sneakers-saucony-jazz-low-pro-vegan. There are a lot of urls with random names, so i cant put all of them into condition directly by hand using full URL path with REQUEST_URI for each product. I try to use

    if ($_SERVER['REQUEST_URI'] == "-saucony"){
$vm = JomGenius("virtuemart"); 
$cat = $vm->info("category_id"); 
if ($cat and $vm->check("pagetype startswith productdetails") ) { 
  $changes->mod(192) 
  ->setParam("virtuemart_category_id",$cat) 
  ->title("Products: " . $vm->info("category_name")) 
  ->showTitle(true); 
  return 192; 
}
}

Solution

  • Currently your outer if statement is checking if the full URL path is completely equal to "-saucony"; it should be checking if the full URL path only contains "-saucony". Use strpos to search for a containing string element.

    if (strpos($_SERVER["REQUEST_URI"],"-saucony") !== false) 
    {
            // code to load product slider
    }