欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal 给内容节点增加链接 有大用 有大大用

1)主题的 template.php 中  hook_precess_node 

function bartik_clone_preprocess_node(&$variables) {
 
if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
   
$variables['classes_array'][] = 'node-full';
 }
 
if(isset($variables['content']['body'][0]['#markup'])  && $variables['teaser']){
   
$variables['content']['body'][0]['#markup'] = _strip_only($variables['content']['body'][0]['#markup'], '<img><iframe><embed><br>');
 }
 
if ($variables['view_mode'] == 'full'){
   
$variables['content']['links'][$variables['type'] = array(
       
'#theme' => 'links__node__blog',//这里 $links__node__blog 的如果未定义,就使用 theme_links 这个函数
       
'#links' => $links,//这里 $links的定义见下面  node_to_word_node_view 这个函数
       
'#attributes' => array('class' => array('links', 'inline')),
   );
 }

}

2)在模块中 hook_node_view 也可以

function node_to_word_node_view($node, $view_mode, $langcode) {
 
$links = array();

 
if (node_to_word_enabled($node->type)) {
   
if (user_access('access node_to_word docs')) {
     
$links['node_to_word_link'] = array(
       
'title' => t('Save as Word'),
       
'href' => "word/$node->nid",
       
'attributes' => array('title' => t('Save this document as a Microsoft Word document.'))
     );
     
$links['node_to_word_txt_link'] = array(
       
'title' => t('Save as text'),
       
'href' => "txt/$node->nid",
       
'attributes' => array('title' => t('Save this document as a plain text document.'))
     );

     
$node->content['links'][$node->type] = array(
       
'#theme' => 'links__node__blog',//这里 $links__node__blog 的如果未定义,就使用 theme_links 这个函数
       
'#links' => $links,
       
'#attributes' => array('class' => array('links', 'inline')),
     );

   }
 }
}


在列表页效果 如下

image.png

在节点详情页,效果如下

image.png

普通分类: