Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By norendahlb on
At the end of a node I have the "Read more", "Comments" and "Add new comment" links...
<ul class="links inline">
<li class="node-readmore first>...</li>
<li class="comment-comments>...</li>
<li class="comment-add last>...</li>
</ul>
Now, I can change/add class(es) to the ul using a function in my template.php as follows:
function MYTHEME_preprocess_comment(&$variables) {
$variables['attributes']['class'][]='new-class";
}
I.e, the classes (links, inline) for the ul are stored in the following array:
$var['content']['links']['comment']['#attributes']['class']
But how can I add a class to the li elements? I've tried so many ways now but I cannot figure it out?!
To be clear, I want to end up with
<code>
<ul class="links inline">
<li class="node-readmore NEW-CLASS first">...</li>
<li class="comment-comments NEW-CLASS">...</li>
<li class="comment-add last NEW-CLASS">...</li>
</ul>
Regards B
Comments
A Helpful Comment Thread
Maybe this will help?
https://api.drupal.org/comment/13419#comment-13419
Thanks
Yeah, maybe. I'm looking into it now. It's a little closer, but still far away.
I don't really get it. For starters I don't know where this code should be written.
I'll keep trying to add to the attributes in the item_list (in my template.php), see if I can figure it out.
The array that represents a
The array that represents a list looks something like this:
When you add your class 'new-class', it looks like this:
The part you have to change is the #items. Each item is a string, you need to turn it into an array. So this:
Needs to become this:
So you'll need to alter $var['content']['links']['comment']['#items'] until it looks like the above.
Thanks again
Really appriciate the help. However, as frustrating as it is, i still can't get it right. Let me recap, if you bare with me.
Currently I have:
Which renders:
I do not want to alter anything inside the comment-comments and comment-add arrays.
I just want to change their names, like
comment-comments > "comment-comments my_class"
comment-add > "comment-add my_class"
So it is infact the #links-array I want to change.
From
[comment-comments, comment-add]
to['comment-comments my_class', 'comment-add my_class']
So that it renders
I only manage to make NEW list items (adding more elements to the #Links array)...and they are empty (nothing between the li-tags). The original ones gets rendered automatically, with number of comments and links to correct places etc.
Again, thanks for your time and effort trying to explain to me how it's done.
I don't know what I'm looking
I don't know what I'm looking at here:
Can you show the output of this:
Ah, that's the way to describe it
That outputs what I was trying to describe in previous post :P
Ok, you should be able to do
Ok, you should be able to do this:
That adds 'some_class' to the
That adds 'some_class' to the content (the link) between the li-tags.
Thoose li-tags sure are hard to alter...
In that case, you probably
In that case, you probably will have to override theme_links(). I don't think you'll be able to do it in a preprocess function.