Eri*_*icP 3 blogs templates drupal
我正在尝试创建一个预告片节点模板来显示所有博客预告片.对于页面tpl我有page-blogs.tpl.php对于Blog节点tpl我有node-blog.tpl.php(这个循环显示所有的博客teasers)现在我如何创建一个节点模板来包围节点戏弄?我的所有博客主页的页面的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>
Run Code Online (Sandbox Code Playgroud)
谢谢
更新:我在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;
}
}
//----
}
Run Code Online (Sandbox Code Playgroud)
假设您的内容类型称为"博客",则只要需要显示博客帖子,就会使用node-blog.tpl.php.如果Drupal需要预告片显示,$ teaser变量将在node-blog.tpl.php中设置为TRUE,如果节点以完整页面视图显示,则$ page变量将设置为TRUE(它们都将是如果整个节点显示在节点列表中,则为FALSE).因此,您需要设置node-blog.tpl.php以检查所请求的显示类型,并返回适合给定类型的HTML.您的node-blog.tpl.php的一般设置应该是这样的:
if($teaser){
//return teaser html
}
else{
//return full node HTML
}
Run Code Online (Sandbox Code Playgroud)
从你的问题来看,我有点不清楚,但听起来你可能在node-blog.tpl.php中有一些循环代码来迭代你网站上的节点.你不想这样做.Drupal不像Wordpress那样工作.
您没有提到如何在/ blogs/eric中生成您的预告片列表,但我建议您使用Views模块.如果您使用Views生成teasers列表,那么您将能够使用Views的主题轻松地对列表进行主题化.
自从您添加了示例代码后编辑 为了将任意HTML粘贴到博客页面的完整节点显示的顶部,您可以编辑node-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>
Run Code Online (Sandbox Code Playgroud)
自从发现你正在使用博客模块以来编辑要在博客 摘要列表的顶部显示任意HTML,只需将其粘贴在页面顶部-blog.tpl.php