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

时间:2013-03-07 21:16:39

标签: php joomla

如何才能在joomla的主页上显示消息? 我有兴趣在site.com上显示它,而不是site.com/index.php/page或其他任何网站。

我测试了以下内容:

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

问题是我仍然可以在http://site.com/index.php/category/id/78-article这样的网页上看到“这是主页”的消息,这显然不是主页。似乎每当链接中有index.php时,上面的代码都认为它属于主页。

3 个答案:

答案 0 :(得分:2)

这与链接中的'index.php'无关。相反,它与http://site.com/index.php/category/id/78-article处的链接没有与之关联的菜单项有关。要完全按照您的要求进行操作,您可能需要对代码有点麻烦,并检查以确保实际页面的信息与主页信息匹配:

$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值与输入中设置的值。

http://site.com/index.php/category/id/78-article此链接会将ID设置为78,并且可能会更改主页菜单中定义的视图和选项,因此不会触发。

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

你应该试试这个。 1.从管理员部分检查已分配的菜单&#34;主页&#34;(这是主页)。复制那里显示的链接。 这就像是

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

    if(JRequest::getVar('option')=='com_something' && JRequest::getVar('view')=='someview'){    //show message    }
    
  3. 这应该为你做的伎俩!!但请记住。如果您更改主页的菜单,则必须相应地更改。

相关问题