Drupal:全视图提取预告片

发布于 2024-09-30 14:59:18 字数 53 浏览 9 评论 0原文

如何将预告片与 node.tpl.php 中的其余内容分开,以将预告片文本包装在特殊标记中?

How can I split the teaser from the rest of the content in the node.tpl.php to wrap the teaser text in special markup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪也成诗 2024-10-07 14:59:18

您可以预处理主题变量来检索预告片并单独存储它,否则 Drupal 会在内部处理它并且不会给您选择。

这是代码: http://www.mydiary.digiprosoft.com/?p=244< /a> 和下面是该链接的重点内容。


template.php

function phptemplate_preprocess_node(&$variables) {
    // we like to display teasers on the node view pages in a different style,
    // but only if they were NOT set to “show summary on full view” (which seems
    // backward, but the implication with that checkbox is that the teaser is
    // PART of the node’s body, instead of an actual summary of the entire
    // node’s body). if a node’s unbuilt body starts with , then
    // a teaser has been manually set, and “show summary” is not checked.
    if ($variables['page'] == TRUE) { // only do this on full page views.
        $node = node_load($variables['nid']); // we reload the node because
        // by the time it gets here has already been filtered out.
        // this if logic stolen from node.module’s node_teaser_include_verify().
        if (strpos($node->body, '') === 0) {
            $variables['style_teaser_differently'] = TRUE;
            $variables['teaser'] = check_markup($node->teaser, $node->format, FALSE);
        }
    }
}

node.tpl.php

<?php
    if ($style_teaser_differently){
        print '<div class="fullview-teaser">'.$teaser.'<div>';
}
?>

You could preprocess the theme variables to retrieve the teaser and store it separately, otherwise Drupal handles it internally and won't give you a choice.

Here is the code: http://www.mydiary.digiprosoft.com/?p=244 and below are the highlights from that link.


In template.php

function phptemplate_preprocess_node(&$variables) {
    // we like to display teasers on the node view pages in a different style,
    // but only if they were NOT set to “show summary on full view” (which seems
    // backward, but the implication with that checkbox is that the teaser is
    // PART of the node’s body, instead of an actual summary of the entire
    // node’s body). if a node’s unbuilt body starts with , then
    // a teaser has been manually set, and “show summary” is not checked.
    if ($variables['page'] == TRUE) { // only do this on full page views.
        $node = node_load($variables['nid']); // we reload the node because
        // by the time it gets here has already been filtered out.
        // this if logic stolen from node.module’s node_teaser_include_verify().
        if (strpos($node->body, '') === 0) {
            $variables['style_teaser_differently'] = TRUE;
            $variables['teaser'] = check_markup($node->teaser, $node->format, FALSE);
        }
    }
}

In node.tpl.php

<?php
    if ($style_teaser_differently){
        print '<div class="fullview-teaser">'.$teaser.'<div>';
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文