Detecting Virtuemart pages through conditional statements

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

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

Virtuemart Conditional Statements

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 your 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 } ?>

Add a Comment

Your email address will not be published. Required fields are marked *

Enjoy best web development services at an affordable price. Looking forward to build a good relationship and serve you better...

ABOUT CODINGACE

My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

Nohman Habib

CEO: codingace.com

Request a Quote