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 maxiorel on
Hello people, is there any way how to change to order how the $links
are displayed? I would like to have the "read more" as the first, then the other links. Any solution working in Drupal 5.1? Thanks.
Comments
You can only alter the order
You can only alter the order by writing some code as far as I know.
You can either alter it in hook_link_alter http://api.drupal.org/api/HEAD/function/hook_link_alter
before they go to the theme engine
or in your theme by providing your own version of
theme_links http://api.drupal.org/api/HEAD/function/theme_links
dLd
Anyone got some example code using theme_links?!
Would be really helpful for php dunces like me. I don't have a clue how to even start reordering the links with php... :(
I agree
Sample code for theme_links would be very helpful. Anyone feel like becoming a hero by sharing some code?
=-=
There is sample code on the api page
Almost a hero...
I was kinda hoping for sample code of a custom written theme_links being used to change the order of the $links... ;)
digging out the links from the links-array
hi,
I was looking for the same thing - originally actually wanted split the links-array into pieces and then put the different parts into different variables so I could use them wherever..
After some browsing and trying out this and that I finally have this working 'code snippet'.. Might be that it's a bit dirty but it does exactly what I want it to do.. (it even hides the page-counter a.k.a. 'statistics_counter' from people who're not allowed to view it)
What came out was then the following code - an override of the theme_links function - digging out the 'add_to_cart' and the 'forward_links' and the 'statistics_counter' from the array $links and making it available for the node.tpl.php files.. - ..can probably also give out whatever parts from the $links..
this goes in the phptemplate:
and then this goes into the node.tpl.php respectively the node-my_content_type.tpl.php wherever you want to display the different links:
hope it helps..:]
greetz, t..
___________________________
my pictures: www.bilderbook.org
___________________________
digging out the links from the links-array
hello tille
this should be moved into the handbook! great!
thanks and greetings
momper
Using hook_links_alter
I found the simplest way to change link order was to merge the links array into a pre-ordered but blank set of links in hook_links_alter as follows. This works because when you merge a new array into an existing one, the original order prevails.
• scott lahteine, thinkyhead.com
Subscribing, still
Subscribing, still struggeling with this, greetings, Martijn
Where do you put this code?
Hi
I don't know much about php, two questions:
1.- Where do you put this php code for ordering the links?
2.- Where do you find the "name" of the links (i.e. "item_buy", "item_permalink", "forward_links", etc...)?
Thanks in advance.
Macarro, you've to create a
Macarro, you've to create a new module or use an existing module. Make use of hook_link_alter(). If created a new module with the name 'custom_kit'. Therefore the name of the hook is 'custom_kit_link_alter(). Here is an working example:
If you want to get the names you've to enter then include the following lines right after function custom_kit_link_alter(&$node, &$links) {
It'll print you the links array and shows you the names. That's it.
My site: TRITUM - Björn Jacob
Check out: AJAX PARTNER
A lot of months later...
Thanks for your help, bjacob. It worked perfectly.
Now I'm on Drupal 6 and I create a mini-module to re-order the links. My PHP skills are not enough to create a good configurable module but I want to share the code because it can help others.
For Drupal 6.x:
...and that's all, now you'll have your links in this order ??? | ... | ??? | comment_ad read_more
Maybe someone can convert this into a "real" module with configurable menus and such kind of things.
FINAL NOTE: hook_link_alter uses the parameters in different order in Drupal 5, so, the only change you should make to use this code in Drupal 5 would be:
Unbelievable! There is no
Unbelievable! There is no module for the management of $links in D7!
However, if you're still on D6, Link Weights, might come in handy sometimes.
Unbelievable! There is no
Sounds like it would be a good module for you to develop and share with the community then.