如何仅在joomla主页上显示消息? [英] How to display a message on joomla homepage only?

查看:147
本文介绍了如何仅在joomla主页上显示消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅在joomla主页上显示消息? 我有兴趣在site.com而不是site.com/index.php/page或site.com上显示它.

How can I display a message only on the homepage of joomla? I am interested in displaying it on site.com and not site.com/index.php/page or anything else then site.com.

我已经测试了以下内容:

I have tested the following:

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

问题是,在

The problem is that I can still see the message "this is the homepage" on pages like http://site.com/index.php/category/id/78-article which clearly isn't the homepage. It seems that whenever there is index.php in the link, the above code thinks it belongs to the homepage.

推荐答案

这与链接中的"index.php"无关.相反,它与以下事实有关: http://site.com/index.php/category/id/78-article 没有与之关联的菜单项.要确切地执行您想要的操作,您可能需要对代码进行一点点技巧,并检查以确保实际页面的信息与主页信息相匹配:

This has nothing to do with the 'index.php' in the link. Instead it is related to the fact that the link at http://site.com/index.php/category/id/78-article does not have a menu item associated with it. To do exactly what you are wanting, you will probably need to get a little trickier with the code and check to make sure that the actual page's information matches the homepage information:

$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值.

I am checking the default menu items option (which component) and view and id values against those set in the input.

http://site.com/index.php/category/id/78条此链接会将ID设置为78,并可能会更改其视图和选项(与主页菜单中的定义相同),因此不会发生触发.

http://site.com/index.php/category/id/78-article This link will set the id to 78 and likely change the view and option from what it is defined as in the menu for the homepage, so the trigger will not occur.

这篇关于如何仅在joomla主页上显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆