【发布时间】:2010-08-23 18:33:05
【问题描述】:
我正在尝试创建一个预告片节点模板来显示所有博客预告片。 对于页面 tpl 我有 page-blogs.tpl.php 对于博客节点 tpl,我有 node-blog.tpl.php (这是循环显示所有博客预告片) 现在如何创建一个节点模板来围绕节点预告片? 我的所有博客预告页面的 URL 是:/blogs/eric 我的带有示例博客条目的页面的 URL 是:/blogs/eric/test-blog-1 我需要一个可用于所有博客页面的节点模板。 我尝试将 node-blogs-teaser.tpl.php 用于单个预告片节点,将 node-blog.tpl.php 用于外部博客节点模板,但这不起作用。
这是我的 node-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;
}
}
//----
}
【问题讨论】: