templates - 博客预告片节点的节点模板

标签 templates drupal blogs

我正在尝试创建一个预告片节点模板来显示所有博客预告片。 对于页面 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;
        }
    }
    //---- 
}

最佳答案

假设您的内容类型称为“博客”,那么每当需要显示博客文章时就会​​使用node-blog.tpl.php。如果 Drupal 希望显示预告片,则在 node-blog.tpl.php 中 $teaser 变量将设置为 TRUE,如果节点以全页 View 显示,则 $page 变量将设置为 TRUE(它们都将是如果完整节点显示在节点列表中,则为 FALSE)。因此,您需要设置 node-blog.tpl.php 来检查所请求的显示类型并返回适合给定类型的 HTML。 node-blog.tpl.php 的一般设置应遵循以下原则:

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

我对你的问题有点不清楚,但听起来你可能在 node-blog.tpl.php 中有某种循环代码来迭代站点上的节点。你不想这样做。 Drupal 的工作方式与 Wordpress 不同。

您没有提到您的预告片列表是如何在/blogs/eric 生成的,但我建议使用 View 模块。如果您使用 View 生成预告片列表,那么您将能够使用 View 的主题轻松设置列表的主题。

自您添加示例代码以来已进行编辑 要将任意 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>

自从发现您正在使用博客模块后进行编辑 要在博客预告片列表的顶部显示任意 HTML,只需将其粘贴在 page-blog.tpl.php 的顶部

关于templates - 博客预告片节点的节点模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3550577/

相关文章:

c++ - std::enable_if 的第二个参数有什么用?

c++ - 使用 C++17 编译时无法从基类访问成员类型

javascript - 整理 Handlebars 文件

复杂关系的 Drupal 最佳实践

php - 在 drupal_goto 之前使用 drupal_add_js

rdf - 博客有 RDF 本体吗?

java - 适用于 Java 的博客软件/平台

templates - 如何使域对象(数据)随处可见? ils子

php - 在每一页的开头重复一个表格

Android WebView 未加载博客