Detecting Virtuemart pages through conditional statements

Share this post on:

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 asked you 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 prepare hidden menus for each product and category pages, which actually takes time and is sometimes 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. 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

The below code will detect and condetion will return true for all virtuemart pages, so for VirtueMart category pages, product pages, or cart pages.

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

Author: Nohman Habib

I basically work in the CMS, like Joomla and WordPress and in framework like Laravel and have keen interest in developing mobile apps by utilizing hybrid technology. I also have experience working in AWS technology. In terms of CMS, I give Joomla the most value because I found it so much user freindly and my clients feel so much easy to manage their project in it.

View all posts by Nohman Habib >

Leave a Reply

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

PHP Code Snippets Powered By : XYZScripts.com