[development] Altering links

Carl Wiedemann carl.wiedemann at gmail.com
Thu Nov 18 20:21:48 UTC 2010


You could achieve it with both CSS and preprocess by doing something like
this:

In your template.php file, mytheme_preprocess_node():

// START
$node = $vars['node'];

if (!empty($node->links['comment_comments'])) {
  // Class depending on node comment count.
  if (!empty($node->comment_count)) {
    $myclass = 'has-comments';
  }
  else {
    $myclass = 'no-comments';
  }

  // Add to particular link class.
  if (empty($node->links['comment_comments']['attributes']['class'])) {
    $node->links['comment_comments']['attributes']['class'] = $myclass;
  }
  else {
    $node->links['comment_comments']['attributes']['class'] .= ' ' .
$myclass;
  }

  // Reformat all links
  $vars['links'] = !empty($node->links) ? theme('links', $node->links,
array('class' => 'links inline')) : '';
}
// END


In your theme's css file

/* START */
.has-comments {
  backgorund-image: url(./images/some-image.png);
  background-repeat: none;
  padding-left: 2em;
}

.no-comments {
  background-image: none;
  padding-left: 0;
}
/* END */





On Thu, Nov 18, 2010 at 1:01 PM, Salvatore De Paolis <iwkse at gmx.com> wrote:

> On Thu, 18 Nov 2010 12:31:23 -0700
> Carl Wiedemann <carl.wiedemann at gmail.com> wrote:
>
> >  $vars['links'] is generated by theme_links(). Look at
> > template_preprocess_node() in includes/theme.inc:
> >
> http://drupalcode.org/viewvc/drupal/drupal/includes/theme.inc?revision=1.415.2.27&view=markup&pathrev=DRUPAL-6-18-SECURITY#l1955
> >
> > $variables['links']     = !empty($node->links) ? theme('links',
> > $node->links, array('class' => 'links inline')) : '';
>
> Yes i misunderstood it, i thought it was some kind of overriding
>
> > Unless you absolutely consider the icons to be content and not styling,
> CSS
> > is the way to go instead of <img> tags. Different CSS classes may be
> applied
> > via theme_links() to indicate whether comments exist. CSS also allows for
> > the use of sprites.
>
> As i said in the previous comment, in some cases, i'd want only the icon
> which
> i suppose i can't achieve only with CSS.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101118/5ea9bf04/attachment.html 


More information about the development mailing list