0

我一直在寻找一整天,但我似乎无法让(任何)钩子工作,特别是这个钩子。我想使用 hook_link_alter 将类(颜色框)添加到预告片上的链接。我能够通过破解核心让它工作,但我当然想要一个更好的解决方案。

node.module 中的相关代码是:

if ($view_mode == 'teaser') {
$node_title_stripped = strip_tags($node->title);
$links['node-readmore'] = array(
  'title' => t('Read more<span class="element-invisible"> about @title</span>', array('@title' => $node_title_stripped)),
 'href' => 'node/' . $node->nid,    
  'html' => TRUE,
  'attributes' => array('rel' => 'tag', 'title' => $node_title_stripped),

);

}

我能够通过添加来实现我想要的

将最后一行(其中包含文本)替换为:'attributes' => array('class' => 'colorbox' 'rel' => 'tag', 'title' => $node_title_stripped),

请帮忙

4

2 回答 2

1

以下代码将有所帮助:

function theme_preprocess_node(&$variables) {
  // if readmore link is set
  if (isset($variables['content']['links']['node']['#links']['node-readmore'])) {

    // remove the old link
    unset($variables['content']['links']['node']['#links']['node-readmore']);

    // Create new link variable
    $variables['content']['links']['node']['#links']['node-readmore-custom'] =  l(t('More >'), $variables['node_url'], array('attributes' => array('class' => t('colorbox'))));

  }
}

之后,您需要在 node.tpl.php 中的主题下的适当位置添加这个新变量。

希望这会有所帮助。

于 2013-04-25T14:29:19.013 回答
0

I don't know much about hooks, but I would use Display Suite: http://drupal.org/project/ds

Make sure you also enable DS Extras, go to Structure->DS and create a CSS Class "colorbox"

Then go edit the content type, manage display, select "teaser", go to the bottom and create a layout (One column).

After saving, select the gear to the right of the link field and select "Expert" in the layout dropdown and "colorbox" in the classes select list.

Once you hit update and save, the field should be rendered with the class.

于 2013-04-26T03:06:17.817 回答