如何将预告片与 node.tpl.php 中的其余内容分开,以将预告片文本包装在特殊标记中?
问问题
1134 次
1 回答
1
您可以预处理主题变量以检索预告片并将其单独存储,否则 Drupal 会在内部处理它并且不会给您选择。
这是代码:http ://www.mydiary.digiprosoft.com/?p=244及以下是该链接的亮点。
在模板.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>';
}
?>
于 2010-11-03T16:23:18.043 回答