Joomla:如何为不同的菜单ID分配不同的布局? [英] Joomla : How can we assign a different layouts to different menu IDs?

查看:96
本文介绍了Joomla:如何为不同的菜单ID分配不同的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Joomla,希望您解决以下问题.

I am running Joomla and seeking you help for the following issue.

让我们说我的模板中有3种布局,布局文件命名为...

Lets say I have 3 layouts in my template and the layout files are named as...

index.php
index2.php
index3.php

我有5个菜单链接....

I have 5 menu links say....

Link 1
Link 2
Link 3
Link 4
Link 5

我正在寻找的是……

对于Link 1, Link 4 and Link 5,我希望Joomla加载常规的index.php,但是对于Link 2,我希望Joomla加载index2.php,对于Link 3,我希望其加载index3.php.

For Link 1, Link 4 and Link 5, I want Joomla to load the regular index.php but for Link 2 I want Joomla to load index2.php and similarly for Link 3 I want it to load index3.php.

我的意思是...我们如何为不同的菜单ID分配不同的布局?

What I mean is... How can we assign a different layouts to different menu IDs?

我知道有一个内置选项可以根据菜单ID选择不同的模板,但是我不想为此功能重复模板文件.我的模板中的所有内容都是相同的,只是布局的变化取决于菜单ID.

I know there is an inbuilt option to choose a different Template based on menu ID but I do not want to duplicate the template files just for this one function. Everything in my templates is the same just the change is in the layout depending on the Menu ID.

请帮助.

推荐答案

您使用的是商业模板还是自定义模板?您应该能够对index.php进行编码,以便布局由页面上加载的模块确定.然后,您可以通过模块参数中的菜单分配来控制显示哪些模块.您可以控制通过CSS,Page Class后缀以及index.php上的代码显示的布局.

Are you using a commercial template or something custom? You should be able to code your index.php so that the layout is determined by the modules loaded on the page. You then control what modules show up by the menu assignments in the module parameters. You can control the layout being displayed through CSS, Page Class Suffix, and the code on index.php.

模板中的每个模块位置都应该是可折叠的-这意味着,如果没有模块加载到该位置,则不会将其添加到HTML中.使用类似这样的内容:

Every module position in your template should be collapsible - meaning that if no modules are loaded to the position, it does not get added to the HTML. Use something like this:

<?php if ($this->countModules('left')) : ?>
    <jdoc:include type="modules" name="left" style="xhtml" />
<?php endif; ?>

您还可以结合使用可以在菜单项的系统参数"上设置的页面类后缀"和CSS来控制页面的布局.我将页面类后缀添加到模板的BODY标签中,以便可以分别控制每个页面.

You can also use a combination of the Page Class Suffix that you can set on the System Parameters of a menu item and CSS to control the layout of the page. I add the Page Class Suffix to the BODY tag of my templates so I can control every page individually.

首先,您需要弄清楚您所在的菜单项:

First, you need to figure out which menu item you are on:

<?php
$menu = &JSite::getMenu();
$active = $menu->getActive();
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;
?>

然后,您需要将其作为ID添加到BODY标签中:

Then you need to add that to the BODY tag as an ID:

<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">

现在,您可以使用模块位置和CSS来控制每个页面.您无需重新输入代码就可以实现截然不同的布局.

Now you can use module positions and CSS to control every page. You can achieve vastly different layouts without having to go back in and touch code.

这篇关于Joomla:如何为不同的菜单ID分配不同的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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