Joomla if else for menu by ID or url

2019-08-26 10:04发布

I have a situation whereby i want two of my pages to look different form the rest but they are not front pages. If they were it would be easy as the code below would do the trick.

$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';

esle(do something else)
 }
?>

In short i want a similar approach but this time, to get the menu by ID/URL. Any ideas?

2条回答
孤傲高冷的网名
2楼-- · 2019-08-26 10:39

Page ItemId can be obtained using $itemid = JRequest::getInt( 'Itemid' );

查看更多
Luminary・发光体
3楼-- · 2019-08-26 10:47

I got the answer to this...all you need to check is the menu ID then put the code below.

<?php
  //This is the code for the page with menu ID 6
  $menuID = JSite::getMenu()->getActive()->id ;
  if ($menuID == '6')
  {
    echo '';
  }
  elseif ($menuID == '2') //This is the HTML for page with menu ID 2
  {
    echo '';
  }
  elseif ($menuID  == '4') //THis is the html for page with menu id 4
  {
    echo '';
  }
  else  //This is the HTML code for the rest of the pages
  {
    echo '';
  }
?>
查看更多
登录 后发表回答