官方系列教材 - H计划

代码生成器

我们在定制 Joomla 网站模板的时候处于排版的需要可能会要求关闭组件输出区,而不是输出空白内容,如果你不知道啥是组件输出区或者我用词不当,请看下面这张图:

这是一张常规 Joomla 模板布 局图,通常我们使用:精选文章列表(joomla 2.5)、头版文章排版(joomla 3.x)来输出空白的网页,然后在上面放置模块来布局页面,尽管页面上看不到任何东西,但是那个空白是真实存在的,尤其在古董级浏览器上面,而且输出的 Html代码里面会有一大串多余的html代码,明显对seo不利。因此我们就需要权重最高的网站首页禁止输出组件区。当然,这不是绝对的,如果你想在首 页输出某些组件的内容,那么这篇文章不太适合你。

下面这段是 Joomla  3.x 系统默认模板 protostar 的组件输出部分代码:

<main id="content" role="main" class="<?php echo $span;?>">
<!-- Begin Content -->
<jdoc:include type="modules" name="position-3" style="xhtml" />
<jdoc:include type="message" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="position-2" style="none" />
<!-- End Content -->
</main>

我们只需要加上一个判断是否是首页的语句就可以了,这个判断语句通常是这样的:

//判断是否首页
$home = 0;
$menuitem = & JSite::getMenu();
if ($menuitem->getActive() == $menuitem->getDefault()) {
$home = "1";
}

组合起来就是下面这样,请勿照本宣科,一定要根据你自己的实际情况使用:

<?php if(!$home): ?>
<main id="content" role="main" class="<?php echo $span;?>">
<!-- Begin Content -->
<jdoc:include type="modules" name="position-3" style="xhtml" />
<jdoc:include type="message" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="position-2" style="none" />
<!-- End Content -->
</main>
<?php endif; ?>

 我们再举个例子:Ja_elastica T3 框架模板

部分T3框架模板在后台提供了是否显示组件去的选项:Hide Main content block //xd:它叫这个名字。奇葩的是,开启之后在所有的页面都不会显示组件区,这明显不是我们想要的,好吧上代码:

//修改前
<?php if (!$this->getParam ('hide_content_block', 0)): ?>
<div id="ja-content" class="ja-content ja-masonry">
<?php
//content-top
if($this->hasBlock('content-top')) :
$block = &$this->getBlockXML ('content-top');
?>
<div id="ja-content-top" class="ja-content-top clearfix">
<?php $this->showBlock ($block); ?>
</div>
<?php endif; ?>

<div id="ja-content-main" class="ja-content-main clearfix">
<?php echo $this->loadBlock ('message') ?>
<?php echo $this->showBlock ('content') ?>
</div>

<?php
//content-bottom
if($this->hasBlock('content-bottom')) :
$block = &$this->getBlockXML ('content-bottom');
?>
<div id="ja-content-bottom" class="ja-content-bottom clearfix">
<?php $this->showBlock ($block); ?>
</div>
<?php endif; ?>

</div>
<?php endif ?>
//修改后
<?php if (!$this->getParam ('hide_content_block', 0) or $home =='0'): ?>
<div id="ja-content" class="ja-content ja-masonry">
<?php
//content-top
if($this->hasBlock('content-top')) :
$block = &$this->getBlockXML ('content-top');
?>
<div id="ja-content-top" class="ja-content-top clearfix">
<?php $this->showBlock ($block); ?>
</div>
<?php endif; ?>

<div id="ja-content-main" class="ja-content-main clearfix">
<?php echo $this->loadBlock ('message') ?>
<?php echo $this->showBlock ('content') ?>
</div>

<?php
//content-bottom
if($this->hasBlock('content-bottom')) :
$block = &$this->getBlockXML ('content-bottom');
?>
<div id="ja-content-bottom" class="ja-content-bottom clearfix">
<?php $this->showBlock ($block); ?>
</div>
<?php endif; ?>

</div>
<?php endif ?>

转载自星仔码头

评论 (0)

  • 最新在前
  • 最佳在前

第1章 经验分享

第2章 专题教程

第3章 扩展推荐

第13章 扩展更新日志