Drupal首页定制

Drupal默认的首页像是一个博客的文章列表,如何定制成自己想要的样子呢?有以下几种方法来实现:

使用Front Page模块

大多数人实现某个功能时首先想到的就是用模块(Front Page首页模块),但个人并不认同动不动就使用模块,太多模块增加系统负担,下面的方法同样解决了定制首页的问题而不必使用模块。

使用page-front.tpl.php页面模板

page-front.tpl.php是首页的页面模板,把page.tpl.php复制并改名为page-front.tpl.php,修改里面的内容就可以定制首页了。

使用node-front.tpl.php节点模板

如果只是更改首页节点显示的样式,仅更改节点级别的模板即可。把node.tpl.php复制并改名为node-front_page.tpl.php,修改里面的节点显示样式。

使用一个page页面作为首页

新建一个page页面,加入html代码,然后选择full html,记住ID号。导航到admin/settings/site-information,在最下面的“Default front page”输入框中,现在默认为node,我们把它改为node/1(注1改为设为首页的page页面的ID号)。

使用block区块

在admin/build/block中逐个定义block的显示属性,把需要显示在首页block的页面可见性(只在下列页面中显示)中填 入<front>,那么这个block仅在首页可见,修改这个block就可以定制首页的内容,同时可以增加多个block在首页显示。

使用drupal自带的$mission变量

$mission变量最大的特点就是只能显示在首页,利用这个特性,我们就可以轻松定制首页了。在admin/settings/site- information中定义mission任务(把首页代码写进去),然后编辑page.tpl.php文件,把$mission移动到想要的位置,如 果文件中没有这个变量,加入以下代码即可:

1 <?php if ($mission): ?>
2         <div id="missions">
3             <?php print $mission; ?>
4         </div>
5 <?php endif; ?>

以上方法可以单独使用,也可以按需要结合起来使用。还有一种办法就是直接使用index.html静态页面,但这已经脱离了drupal,因此并不推荐。



移除首页"Add new content"的方法  不指定

Just add this code to the page.tpl.php or page--front.tpl.php on Drupal 7.
找到以下代码并替换:
find

<?php print render($page['content']); ?>

and replace with below code.

<?php  if(drupal_is_front_page())
                {
                    unset($page['content']['system_main']['default_message']);
            } 
        print render($page['content']); 
    ?>


And i believe you surely get all blocks or contents you posted on page.

and to remove page title on page like Welcome to "website name"
移除页面标题"website name"
find this code on page.tpl.php or page--front.tpl.php

<?php if ($title): ?><h1 class="title" id="page-title"><?php  print $title; ?></h1>
<?php endif; ?>

and you can remove this code or else just make a comment over.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章