问题描述
如何只在joomla的首页显示一条消息?我有兴趣在 site.com 上显示它,而不是在 site.com/index.php/page 或其他任何网站上显示它.
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";
}
?>
问题是我仍然可以在诸如http://site.com/index.php/category/id/78-article 这显然不是主页.好像只要链接里有index.php,上面的代码就认为是首页的.
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-article 此链接会将 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 主页上显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)