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.

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