Php 如何仅在joomla主页上显示消息?

Php 如何仅在joomla主页上显示消息?,php,joomla,Php,Joomla,如何仅在joomla的主页上显示消息? 我对在site.com上显示它感兴趣,而不是site.com/index.php/page或site.com以外的任何东西 我已测试了以下各项: <?php $app = JFactory::getApplication(); $menu = $app->getMenu(); $lang = JFactory::getLanguage(); if ($menu->getActive() == $menu-&g

如何仅在joomla的主页上显示消息? 我对在site.com上显示它感兴趣,而不是site.com/index.php/page或site.com以外的任何东西

我已测试了以下各项:

    <?php $app = JFactory::getApplication(); 
    $menu = $app->getMenu(); 
    $lang = JFactory::getLanguage(); 
if ($menu->getActive() == $menu->getDefault($lang->getTag())) : ?>this is the homepage
    <?php endif; ?>
这是主页
还有这个

<?php $menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
    echo "this is the homepage";
}
?>


问题是,我仍然可以在这样的页面上看到“这是主页”的消息,而这些页面显然不是主页。似乎每当链接中有index.php时,上面的代码都认为它属于主页。

好的,只是一个想法,但请尝试:

if (preg_match('/index\.php$/',$_SERVER['PHP_SELF'])) {
  echo "this is the homepage";
 }

这与链接中的“index.php”无关。相反,它与这样一个事实有关,即处的链接没有与其关联的菜单项。要准确地执行您想要的操作,您可能需要对代码进行一些修改,并检查以确保实际页面的信息与主页信息匹配:

$jinput = JFactory::getApplication()->input;
$menu = & JSite::getMenu();
$active = $menu->getActive();
$default = $menu->getDefault();
if (
    $active == $default && 
    $jinput->get('option') == $default->query['option'] && 
    $jinput->get('view') == $default->query['view'] && 
    $jinput->get('id') == $default->query['id']
) {
    echo "This is the homepage";
}
我正在对照输入中设置的默认菜单项选项(哪个组件)以及视图和id值进行检查

此链接将id设置为78,并可能更改主页菜单中定义的视图和选项,因此不会发生触发。

您应该尝试此操作。 1.从管理员部分查看已分配“主页”(这是主页)的菜单。复制那边显示的链接。 大概是

index.php?option=com_somecomponent&view=someview
  • 现在转到模板中的index.php
  • 在那里写一个条件

    if(JRequest::getVar('option')=='com_something' && JRequest::getVar('view')=='someview'){    //show message    }
    

  • 这应该对你有用!!但请记住。如果您更改主页的菜单,则必须相应更改此菜单。

    您使用的joomla版本是什么?您可以更好地了解如何查看主页Nice+1,只需在开头键入一个错误
    $jinput
    谢谢!修正了打字错误,这意味着它们都是$jinput,因为文档中通常都是这样。