如何定制每个node下的links

有些小窍门其实很简单,但如果需要的时候一下子又想不起来当初是怎么实现的,所以还是有必要记录一下。比如要修改每个node下的links,就是:“admin's blog, Add comments ..."那一行。在theme里,那一行是通过theme_links来显示的,而使用的$links变量实际上是一个associate array,只要修改相应的数组项就行了。

比如,如果是个人的blog,前面那个admin's blog链接就有些多余,要去掉它很简单:
在theme的node.tpl.php文件里,把下面这行
   <div class="links"><?php print $links; ?></div>


替换成下面这行就可以了
      <div class="links"><?php $mylinks = $node->links; unset($mylinks['blog_usernames_blog']); print theme('links', $mylinks, array('class' => 'links inline')); ?></div>

Comments

1 - 只是娱乐 (未验证)
抓紧学习,正考虑转到drupal

发表新评论

此内容将保密,不会被其他人看见。
  • 允许的 HTML 标签: <blockquote> <div> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • You can use BBCode tags in the text, URLs will automatically be converted to links.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Every instance of "<!--tableofcontents-->" in the input text will be replaced with a collapsible mediawiki-style table of contents. Accepts options for title, list style, minimum heading level, and maximum heading level as follows: <!--tableofcontents list: ol; title: Table of Contents; minlevel: 1; maxlevel: 3;-->. All arguments are optional and defaults are shown.
  • Every instance heading tags will be modified to include an id attribute for anchor linking.
  • Images can be added to this post.
  • 网页地址和电子邮件地址将会被自动转换为链接。

更多格式化选项信息