在Joomla单元/分类介绍中插入模块

应用心得 Add comments

近来在测试Joomla,想实现的一个功能是将Joomla中的模块加入到单元/分类的介绍中,在后台管理中似乎没有这样的设置,而修改模板index.html文件,增加新的position也无法达到想要的效果。最后在Joomla!中文技术讨论区中寻求帮助,终于找到了解决方法。

一、最新版(1.5.3以上)中,可以在单元/分类介绍中直接加入如下代码:

{loadposition ***}

然后在模块管理中,将希望插入到介绍部分的模块位置设置为***(与loadposition后面的位置一致)。这样就可以在介绍部分插入相应的模板了,但是因为css的问题,模块样式会消失。要如何实现css,我还没有测试,大概可以通过模块管理中的css后缀,进行修改。

二、其他版本(1.5.*)安装loadmodule_for_category_description_v1.5插件,可以在文章中任意位置加入模块

  1. 下载安装。安装时,在joomla后台管理:扩展-》安装卸载—》上传压缩包文件-》选择下载好的zip文件进行安装
  2. 在扩展-》插件管理中启用loadmodule for Section/Category Description
  3. 在分类介绍模板中增加触发器
    • 打开<Joomla root folder>/components/com_content/views/category, 找到view.html.php
    • 打开该文件,转到39行,在其后加入下面的代码
    • $category    =&amp; $this-&gt;get('Category');
      $dispatcher    =&amp; JDispatcher::getInstance();
      JPluginHelper::importPlugin('content');
      $results = $dispatcher-&gt;trigger('onBeforeDisplayTitle', array (&amp; $category));
    • 保存
  4. 在单元介绍模板中增加触发器
    • 打开<Joomla root folder>/components/com_content/views/section, 找到view.html.php
    • 打开该文件,转到39行,在其后加入下面的代码
    • $section    =&amp; $this-&gt;get('Section');
      $dispatcher    =&amp; JDispatcher::getInstance();
      JPluginHelper::importPlugin('content');
      $results = $dispatcher-&gt;trigger('onBeforeDisplayTitle', array (&amp; $section));
    • 转到87行,加入
    • $dispatcher =&amp; JDispatcher::getInstance();
      JPluginHelper::importPlugin('content');
      for($i = 0; $i &lt; count($categories); $i++)
      {
      $category =&amp; $categories[$i];
      $category-&gt;link = JRoute::_('index.php?view=category&amp;id='.
      $category-&gt;slug);
      $results=$dispatcher-&gt;trigger('onBeforeDisplayTitle', array(&amp;$category));
      }
      if ($total == 0) {
      $params-&gt;set('show_categories', false);
      }
    • 保存
  5. 在单元/分类介绍,或者文章内容的任意地方加入{loadposition ***},然后再在模块管理中设置模块位置为***,就可以实现在介绍或者文章中插入模块。

参考内容:

更新:
文章中提到新增加的模块css问题,可以在单元/分类介绍中使用HTML编辑,这样就可以设置新加入模块的css了,例如:

<div class = "module heading">
{loadposition ***}
</div>

Related posts

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS 登录