I want to know how to break up the parts of the $links variable in a themed node

for instance

I know print $links will display things like comment, blog link and the service links digg image

how could i split these apart

I know this is wrong but maybe it will give you an idea of what i am trying to do

print $comment_links
print $blog_link
print $service_links

Thanks

Comments

nevets’s picture

If you have access to $node (for example in node.tpl.php) you can access the links as an array using $node->links. Each element of the array is an array.

Jeff Burnz’s picture

Print the links array to see whats there...

<pre><?php print_r($node->links)?></pre>
netentropy’s picture

So then I can just implode the array?

netentropy’s picture

this tells me what array is displayed on the page

but i want to know

how can i just recreate the comment portion of the $links variable with all the same functions as comments whether logged in or not

taqwa’s picture

were you able to figure out how to do this?

kmadel’s picture

I believe you should just be able to change permissions for who can create comments - add the anonymous role.

summit’s picture

Subscribing, whats on $links, greetings, Martijn

netentropy’s picture

i still don't see how to do this

i need to separately call the comments and the read more

not just have it display by calling $links

summit’s picture

Hi,

So could I put

<pre><?php print ($node->links[1])?></pre>

in page.tpl.php to only get element 1 of the $links array? Is that what this thread says?
I will try this. Now not behind pc where I have access to my source.

Greetings,
Martijn

ytorf’s picture

Hi,

Did anyone have any luck with this? About to try what Summit/Martijn suggested.

Georg

summit’s picture

Hi, No it didn't work for me somehow..sorry for the late response. Someone else have a suggestion?

cbroberts26’s picture

My task was to get rid of the "add comment" option on a taxonomy term page, among some other modifications. To separate the array elements in $link and only display the "Read more" link, in node.tpl.php I replaced

print $links;

with this:

print "<a href='/".$node->links["node_read_more"]["href"]."' title='".$node->links["node_read_more"]["attributes"]["title"]."..' >".$node->links["node_read_more"]["title"]."</a>";

I couldn't get it to work using index numbers (i.e., $node->links[0][1]). I had to use the string values. That appears to be the trick.

Note the forward slash inserted at the beginning of the link. That's important.

aschiwi’s picture

cbroberts26, THANK YOU. this was not easy, tried a bunch of things and yours finally got me the right solution. I think you wrote your code for Drupal 5? The following worked for me in Drupal 6 (there your code got me 2 links, one empty and one correct):

print " 
// the following line shows the "read more" link
".$node->links["node_read_more"]["href"]." ".$node->links["node_read_more"]["title"]."
// the following line shows the "add comment" link
".$node->links["comment_add"]["href"]." ".$node->links["comment_add"]["title"]."
";

And this following code shows what variables are available at all:

<pre><?php print_r($node->links)

?>

netentropy’s picture

why does something like $links[0] and $links[1] not work?

WorldFallz’s picture

Because the links variable is an associative array with string keys.

As an aside, I find it much easier and more intuitive to alter the links array with theme_links in the template.php file.

netentropy’s picture

ues but even using the string key in the brackets does not work

how does this theme function help you seperate them

WorldFallz’s picture

It allows you to do whatever you want to the links before they are rendered. For example, to remove the 'user's blog' link you could do:

<?php
function phptemplate_links($links, $attributes = array()) {
    unset($links['blog_usernames_blog']);
    return theme_links($links, $attributes);
}
?>

It all depends on what you want to do.

wooody’s picture

Thank you WorldFallz , Works with me .

Gastonia’s picture

Could someone post a drupal 7 solution please?