[support] How to override term links rendering
Daniel Caillibaud
ml at lairdutemps.org
Fri May 29 10:18:20 UTC 2009
Le 28/05/09 à 09:44, Dale McGladdery <torelad at gmail.com> a écrit :
> The value of $terms is generated in the theme layer so it's
> appropriate to modify it there. Check out:
> http://api.drupal.org/api/function/template_preprocess_node/6
>
> First, a $taxonomy variable is created with: $variables['taxonomy'] =
> taxonomy_link('taxonomy terms', $node);
>
> The value of $terms is created with: $variables['terms'] =
> theme('links', $variables['taxonomy'], array('class' => 'links
> inline'));
>
> Check out the theme_links doc
> (http://api.drupal.org/api/function/theme_links/6). If you can't add
> your CSS the way you want to using the $attributes parameter, you'll
> need to create a custom function.
Thanks a lot. I finally use link_alter (see below)
> On Wed, May 27, 2009 at 4:55 PM, Daniel Caillibaud <ml at lairdutemps.org> wrote:
> > Hi,
> >
> > Hi want to add some own css class in taxonomy terms links (depending on vocabulary), and change links order (depending on
> > vocabularies too).
> >
> > "How?" is the question!
> >
> > - link_alter hook doesn't seem to be the right place because I don't find any param to add css class, and it doesn't play
> > with links order.
I was wrong.
It's possible to add a 'class' attribute to links, and taxonomy links come all together, so it's possible to reorder if wanted.
the solution I took :
function edulibre_link_alter(&$links, $node) {
// we just want to alter taxonomy terms
if (strpos(key($links), 'taxonomy_term_') !== FALSE) {
// our vocabularies specific css classes
$classes = array(
VID_KEYWORDS => 'keywords',
VID_TYPE => 'type',
VID_LEVEL => 'level',
VID_SUBJECT => 'subject',
);
foreach ($links as $key => &$link) {
$link['attributes']['class'] = $classes[$node->taxonomy[substr($key, 14)]->vid];
}
}
}
I don't play with order here, because I saw it's enough to change vocabularies order in admin/content/taxonomy.
> > - it's possible to modify $terms html string in the preprocess_node function (in template.php), but it's doesn't sound like
> > a clean way...
> >
> > I'll apreciate any clue ;-)
> >
> > --
> > Daniel
--
Daniel
More information about the support
mailing list