2010-08-23 65 views
3

我正在嘗試創建一個傳情節點模板以顯示所有博客特技。 對於頁面tpl我有page-blogs.tpl.php 對於博客節點tpl我有node-blog.tpl.php(這是一個循環顯示所有的博客teasers) 現在我該如何創建一個節點模板圍繞節點戲弄者? 我與所有的博客玩笑的頁面的URL是:/博客/埃裏克 我的網頁與博客條目的例子是:/ blogs/eric/test-blog-1 我需要一個我可以使用的節點模板爲所有博客頁面。 我嘗試使用node-blogs-teaser.tpl.php作爲單獨的teaser節點,並使用node-blog.tpl.php作爲外部博客節點模板,但這並不奏效。博客傳情節點的節點模板

以下是我在我的節點blog.tpl.php文件:

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>"> 
<div class="item"> 
<ul> 
<?php print $picture ?> 

<?php if ($page == 0): ?> 
<?php endif; ?> 

    <div class="content clear-block"> 

    <li class="title"><h4><?php print $title ?></h4></li> 
    <li class="photo"><a href="#"><img src="/<?php print $node->field_blog_image[0]['filepath']; ?>" /></a></li> 
    <li class="desc"><?php print $node->content['body']['#value']; ?></li> 
    <li class="link"> 
    <?php if ($teaser): ?> 
    <a href="<?php print $node_url ?>" class="block-link">Read more</a> | <a href="<?php print $node_url ?>" class="block-link">Audio/Video</a> | 
    <?php endif; ?> 
    <?php print $submitted; ?> 
    </li> 
    <div class="clear"></div>  

    </div> 

    <div class="clear-block"> 
    <div class="meta"> 
    <?php if ($taxonomy): ?> 
     <div class="terms"><?php print $terms ?></div> 
    <?php endif;?> 
    </div> 

    </div> 
</ul> 
</div> 
</div> 

感謝

更新:我加入的template.php頁面預處理功能:

/** 
* Override or insert PHPTemplate variables into the templates. 
* These are the main outer templates such as page.tpl.php 
*/ 
function phptemplate_preprocess_page(&$vars) { 

    // add template hints using path alias 
    $alias = drupal_get_path_alias($_GET['q']); 
    if ($alias != $_GET['q']) { 
     $template_filename = 'page'; 
     foreach (explode('/', $alias) as $path_part) { 
      $template_filename = $template_filename . '-' . $path_part; 
      $vars['template_files'][] = $template_filename; 
     } 
    } 
    //---- 
} 

回答

6

假設您的內容類型被稱爲「博客」,那麼只要需要顯示博客文章,就會使用node-blog.tpl.php。如果Drupal需要預覽顯示,$ teaser變量將在node-blog.tpl.php中設置爲TRUE,並且如果節點以全頁面視圖顯示,$ page變量將設置爲TRUE(它們都將是假如節點列表中顯示完整節點,則爲FALSE)。因此,您需要設置您的node-blog.tpl.php來檢查請求的顯示類型,並返回適合給定類型的HTML。您的節點blog.tpl.php的一般設置應該是沿着這些線路:

if($teaser){ 
    //return teaser html 
} 
else{ 
    //return full node HTML 
} 

這是從你的問題一點我不清楚,但它聽起來像是你可能有某種的節點 - 循環碼blog.tpl.php遍歷您網站上的節點。你不想這樣做。 Drupal不能像Wordpress一樣工作。

你沒有提及你在/ blogs/eric中生成的玩家列表,但我建議使用Views模塊。如果您使用視圖來生成戲弄列表,那麼您可以使用視圖的主題輕鬆地將列表主題化。

編輯,因爲你加入你的示例代碼 要只有一個博客頁面的全部節點顯示屏頂部粘任意HTML您可以編輯您的節點blog.tpl.php看起來是這樣的:

<?php if ($page): ?> 
My arbitrary HTML here which will not show up in teasers and only at the top of full blog pages 
<?php endif; ?> 

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>"> 
<div class="item"> 
<ul> 
<?php print $picture ?> 

<?php if ($page == 0): ?> 
<?php endif; ?> 

    <div class="content clear-block"> 

    <li class="title"><h4><?php print $title ?></h4></li> 
    <li class="photo"><a href="#"><img src="/<?php print $node->field_blog_image[0]['filepath']; ?>" /></a></li> 
    <li class="desc"><?php print $node->content['body']['#value']; ?></li> 
    <li class="link"> 
    <?php if ($teaser): ?> 
    <a href="<?php print $node_url ?>" class="block-link">Read more</a> | <a href="<?php print $node_url ?>" class="block-link">Audio/Video</a> | 
    <?php endif; ?> 
    <?php print $submitted; ?> 
    </li> 
    <div class="clear"></div>  

    </div> 

    <div class="clear-block"> 
    <div class="meta"> 
    <?php if ($taxonomy): ?> 
     <div class="terms"><?php print $terms ?></div> 
    <?php endif;?> 
    </div> 

    </div> 
</ul> 
</div> 
</div> 

編輯,因爲查不到你使用博客模塊 要在博客玩笑上市的頂部顯示任意HTML只是把它貼在頁面blog.tpl.php

+0

由於頂部亞倫。 我沒有循環任何東西,我試圖說我注意到node-blog.tpl.php正在用於每個節點傳情。所以在頁面/博客/ eric上,它似乎在爲每個傳情者調用tpl文件。我想要的是每個博客頁面上方的標準標題不重複。我想要這個博客預告頁面和博客整版頁面。 感謝您的幫助 – EricP 2010-08-23 19:02:31

+0

什麼是/博客/埃裏克這是顯示博客條目列表?它是一個視圖或另一個模塊提供該頁面? – Aaron 2010-08-23 19:04:18

+0

對於/ blogs/eric我有page-blogs.tpl.php作爲我的主要模板,它正在打印<?php print $ content?>。 我粘貼了我在node-blog.tpl中的內容。PHP文件在我原來的帖子。 我沒有使用任何意見。 – EricP 2010-08-23 19:09:14