Here in this post I am sharing a way to detect if your current visited page is a VirtueMart page, VirtueMart category page or VirtueMart product detail page.

I think most of you have experience that when your client asks to show/hide any particular section from VirtueMart pages so that might be from sidebar or somewhere else and that was placed in default template file. Now in this case you have only 2 option so either to prepare a new template for VirtueMart pages or by preparing hidden menus for each product and category pages, which actually takes time and sometime not feasible in case of large number of products and categories.

So to eliminate such a situation you can place conditional statements to detect virtuemart pages, which is quite simple and easy to manage and for that you simply have to place the below code in you template’s index.php to show/hide any section, module or else very easily.

Condition to Detect – If Virtuemart Page

Below code will detect and condetion will return true for all virtuemart pages so for VirtueMart Category page, product page or cart page

<?php
/* getting value in “Option” variable */
$option = JRequest::getString('option', null);  
?> 
<?php /* check if it is VirtueMart page or grabbing content using com_virtuemart*/ if ($option == 'com_virtuemart') { ?> Yes this is a VirtueMart page and you can place your module or else by replacing this line <?php } ?>

Condition to Detect – If Virtuemart Category Page

<?php 
/* getting value in “view” variable */ 
$view= JRequest::getString('view', null); 
?>

<?php 
/* check if it is VirtueMart  category page*/
if ($view == 'category') 
{ ? >
  Yes this is a VirtueMart  category page and you can place your module or else by replacing this line
<?php } ?>

Condition to Detect – If Virtuemart Product or product detail Page

<?php 
/* getting  value in “view” variable */
$view = JRequest::getString(view, null);   
?>

<?php 
/* check if  it is VirtueMart product detail page*/
if ($view == 'productdetails') 
{ ? >
  Yes this is a  virtueMart product detail page and you can place your module or else by  replacing this line
<?php } ?>

Related posts:

avatar

Author: