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. - 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 ;-)
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.
On Wed, May 27, 2009 at 4:55 PM, Daniel Caillibaud ml@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.
- 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
Si l'intelligence artificielle fait une connerie, c'est pas grave, c'est une connerie artificielle. -- [ Drupal support list | http://lists.drupal.org/ ]
Le 28/05/09 à 09:44, Dale McGladdery torelad@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@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
Nice
On Fri, May 29, 2009 at 3:18 AM, Daniel Caillibaud ml@lairdutemps.org wrote:
Le 28/05/09 à 09:44, Dale McGladdery torelad@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@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 -- [ Drupal support list | http://lists.drupal.org/ ]