【问题标题】:Different boxes for each modules inside sidebar module position侧边栏模块位置内每个模块的不同框
【发布时间】:2012-09-04 09:16:35
【问题描述】:

我制作了一个 Joomla 2.5 模板。你可以看看这个网站:www.ranfar.com。

查看侧边栏的代码。到目前为止,我有类似的东西:

<div id="sidebar">
    <!-- Here starts the first widget -->
    <h3>Widget title</h3>
    <ul>......... <!-- Module content --> ..........</ul>
    <!-- Here starts the second module -->
    <p>.... <!-- Second module content --> .........</p>
</div>

如您所见,我没有为每个小部件设置单独的框。我想要类似以下内容:

<div id="sidebar">
    <!-- Here starts the first module -->
    <div class="sidebar-module-box">
         <h3>Module title</h3>
         <ul>......... <!-- Module content --> ..........</ul>
    </div>
    <!-- Here starts the second module -->
    <div class="sidebar-module-box">
         <p>.... <!-- Second module content --> .........</p>
    </div>
</div>

通过这种方式,我可以为模块框设置类的样式。 我如何实现这样的模板?我必须在哪里添加它?这是我在 index.php 中生成侧边栏的代码:

<?php if($this->countModules('ranfar-rightsidebar')) : ?>
    <div id="right-sidebar" class="float-right">
        <jdoc:include type="modules" name="ranfar-rightsidebar" style="sidebar" />
    </div> 
<?php endif; ?>

【问题讨论】:

    标签: joomla joomla2.5


    【解决方案1】:

    我找到了解决办法。

    我必须打开文件/templates/THEME/html/modules.php,其中THEME 是我的主题名称。有如下函数:

    function modChrome_sidebar($module, &$params, &$attribs)
    {
        if (!empty ($module->content)) : ?>
            <?php if ($module->showtitle) : ?>
                <h3><?php echo $module->title; ?></h3>
            <?php endif; ?>
            <?php echo $module->content; ?>
        <?php endif;
    }
    

    我不得不改变它如下:

    function modChrome_sidebar($module, &$params, &$attribs)
    {
        if (!empty ($module->content)) : ?>
            <div class="module-box">
            <?php if ($module->showtitle) : ?>
                <h3><?php echo $module->title; ?></h3>
            <?php endif; ?>
            <?php echo $module->content; ?>
            </div>
        <?php endif;
    }
    

    现在每个模块都包含在一个带有“module-box”类的 div 中。

    【讨论】:

    • 你应该选择这个作为正确答案。这是控制模块 chrome 的标准方式。
    【解决方案2】:

    在 Joomla 中,它们被称为模块(而不是小部件)。在您的 XML 文件中,您需要添加模块位置,如下所示:

    <positions>
        <position>login</position>
        <position>search</position>
        <position>sidebar1</position>       
        <position>sidebar2</position>
        <position>etc...</position>
    </positions>
    

    在您的模板中,然后使用上面的代码添加每个模块位置:

    <jdoc:include type="modules" name="sidebar1" style="xhtml" />
    

    无论你在哪里,Joomla 都会在它的位置显示模块(下一段)。关于“风格”的快速说明 - 您可以发送 custom one or use one of the ones Joomla has already depending on your markup needs。

    然后,在模块管理器中,创建一个新模块并选择您希望它出现的位置。

    【讨论】:

    • 对不起,我称它们为小部件,但我知道它们被称为模块。我已经在该位置添加了模块位置和模块。我的问题是关于将每个模块包含在一个具有特定类的 div 中,该特定类对于添加到该位置的所有模块必须相同。我应该为他们创建自定义样式吗?
    • 当然,或者如果你想让它做一些不同的事情,你可以为模块使用模板覆盖——它们真的很有用:docs.joomla.org/… 虽然已经过时,但大部分仍然相关并且更好的解释:docs.joomla.org/Understanding_Output_Overrides
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    相关资源
    最近更新 更多