将日期和作者添加到node.tpl.php

发布于 2024-11-16 20:05:17 字数 888 浏览 0 评论 0原文

在下面的代码中,我想显示创建日期、作者并链接它们,但没有显示任何内容。我相信我需要做 $node-> 而不是那一行,还没有弄清楚确切的代码。或者,如果我需要在 Drupal 6 安装中的“视图”下更改任何内容,该怎么办?提前致谢!

<?php if($node->type == 'blog'): ?>
  <div class="blog-page">
    <div class="title-post">
        <div class="top-image">
            <?php print $node->field_image[0]['view'] ?>
        </div><!--TOP-IMAGE-->
        <p>Posted on <a href="<?php $row['path'] ?>">?php $row['created'] ?></a>, by 
        <a href="<?php print url('blog/author/'.$row['uid']) ?>"><?php print $row['name'] ?></a></p>
    </div>
    <div class="content-page">
        <?php print $node->content['body']['#value'] ?>
    </div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>

In the code below I'd like to show the created date, author and have them be linked but nothing for they do not show. I believe I need to be doing $node-> rather that row, haven't figured out the exact code. Or what if anything I need to change under Views in my Drupal 6 installation. Thanks in advance!

<?php if($node->type == 'blog'): ?>
  <div class="blog-page">
    <div class="title-post">
        <div class="top-image">
            <?php print $node->field_image[0]['view'] ?>
        </div><!--TOP-IMAGE-->
        <p>Posted on <a href="<?php $row['path'] ?>">?php $row['created'] ?></a>, by 
        <a href="<?php print url('blog/author/'.$row['uid']) ?>"><?php print $row['name'] ?></a></p>
    </div>
    <div class="content-page">
        <?php print $node->content['body']['#value'] ?>
    </div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>

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

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

发布评论

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

评论(1

尝蛊 2024-11-23 20:05:17

Drupal 有一个节点对象,其中包含大量相关信息。基本上,如果您需要使用其中的信息,如作者、日期、标题等,您可以通过打印节点对象轻松确定代码。

echo '<pre>';
print_r($node);
echo '</pre>';

为了简单起见,可以说它输出了这样的内容:

stdClass {

  nid = 3
  content = stdClass {
           raw = " ... "
           clean = " ... "
        }

}

要在模板中输出这些信息,您可以按以下方式编写。

对于没有子类的字段:

<?php print $node->nid ?>

对于有子类的字段:

<?php print $node->content['raw'] ?>

这有意义吗?当你把它记下来之后,你就可以在编写 drupal 模板时弄清楚任何事情了。

所以,如果你想构造一个 url,你只需将它链接起来:

<?php
  $nid = $node->nid;
  $uri = "some/path".$nid;
  print $uri;
?>

Drupal has a node object with tons of related information in it. Basically if you ever need to use information from it like author, date, title, etc, you can easily determine the code by printing the node object.

echo '<pre>';
print_r($node);
echo '</pre>';

lets say it outputted something like this for simplicity's sake:

stdClass {

  nid = 3
  content = stdClass {
           raw = " ... "
           clean = " ... "
        }

}

To output those bits of information in your template, you'd write in the following way.

for a field with no subclass:

<?php print $node->nid ?>

for a field with a subclass:

<?php print $node->content['raw'] ?>

Does that make sense? after you get that down, you literally can figure out anything when programming drupal templates.

so, if you wanted to construct a url, you'd just chain it up:

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