Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Joomla if else按ID或url显示菜单_Php_Url_Joomla_If Statement - Fatal编程技术网

Php Joomla if else按ID或url显示菜单

Php Joomla if else按ID或url显示菜单,php,url,joomla,if-statement,Php,Url,Joomla,If Statement,我有一种情况,我希望我的两个页面看起来与其他页面不同,但它们不是头版。如果他们是,这将是很容易的,因为下面的代码会做的把戏 $menu = & JSite::getMenu(); if ($menu->getActive() == $menu->getDefault()) { echo 'This is the front page'; esle(do something else) } ?> 简而言之,我想要一种类似的方法,但这次是通过ID/URL获取菜单。有什

我有一种情况,我希望我的两个页面看起来与其他页面不同,但它们不是头版。如果他们是,这将是很容易的,因为下面的代码会做的把戏

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

esle(do something else)
 }
?>

简而言之,我想要一种类似的方法,但这次是通过ID/URL获取菜单。有什么想法吗?

可以使用
$ItemId=JRequest::getInt('ItemId')获得页面ItemId

可以使用
$ItemId=JRequest::getInt('ItemId')获取页面ItemId

我得到了这个问题的答案……您只需检查菜单ID,然后将代码放在下面

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

我找到了答案……您只需检查菜单ID,然后将代码放在下面

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


请指定您正在使用的Joomla版本请指定您正在使用的Joomla版本Joey很好用,但是我如何才能为一些添加多个id,我已经尝试了
($menuID='5,20,25')
,但它不起作用。@bybe您所要做的就是使用or PHP操作符。类似这样的($menuID==“5”|“20”|“25”){//把你的代码放在这里}嗨,乔伊,谢谢你回复我。我已经尝试了
if($menuID==“115”|“116”|“117”|“118”|“119”){echo'http://schema.org/Product“;}否则{echo”http://schema.org/LocalBusiness“;}
但其他方法似乎不起作用。使用产品和忽略其他内容的所有页面。有什么线索吗?乔伊,这很好,但是我怎么能给一些添加多个id呢?我试过
($menuID=='5,20,25')
,但它不起作用。@bybe你所要做的就是使用or或PHP操作符。类似这样的($menuID==“5”|“20”|“25”){//把你的代码放在这里}嗨,乔伊,谢谢你回复我。我已经尝试了
if($menuID==“115”|“116”|“117”|“118”|“119”){echo'http://schema.org/Product“;}否则{echo”http://schema.org/LocalBusiness“;}
但其他方法似乎不起作用。使用产品和忽略其他内容的所有页面。有线索吗?