30 Apr 2017

PHP Conditional based on a specific K2 item ID

Here's a very handy snippet to create a PHP conditional if statement based on a specific K2 item ID:


<?php
$itemid = JRequest::getInt('Itemid');

if( $itemid == 123 ) {
echo 'do something';
} else {
echo 'these are not the droids you are looking for';
}
?>


<?php
$itemid = JRequest::getInt('Itemid');

if( $itemid == 123 ) {
echo 'do something';
} else {
echo 'these are not the droids you are looking for';
}
?>

The code above can be altered using the following hooks from the page URL:


$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$layout = JRequest::getCmd('layout');
$page = JRequest::getCmd('page');
$task = JRequest::getCmd('task');
$id = JRequest::getInt('id');