Posted by thepocketgeek on May 28, 2010 at 6:10pm
I am trying to format the [username]'s blog, Add new comment and AddThis buttons that I have at the bottom of my blog nodes. I took a look at the structure of the page using firebug and I see that it is called like this:
<ul class="links inline">
<li class="blog_usernames_blog first">
<a title"Really long title" href="/blog/1">user's blog</a></li>and so on...
So I tried to apply some CSS to ul.links but was not able to affect anything. What am I missing?

Comments
If you are trying to change
If you are trying to change the output, this is the best way I think.
http://drupal.org/node/78562#comment-250863
Gil Creque
Hmm...
In looking at node.tpl.php, here is where it calls the links:
<?php if ($links) { ?><div class="links"><?php print $links?></div><?php }; ?>The only thing I have been able to successfully do is clear it from the images above it and that was after adding a div id with clear:both as the css attached to it. What if I wanted to affect changes to the way the links are displayed? Instead of the inline as it currently is called, in a regular list? Maybe this is a better question... Where is the variable $links created?
I think you might be looking
I think you might be looking for something like this http://drupal.org/node/44708
http://api.drupal.org/api/function/hook_link
Gil Creque
I looked through that thread
I looked through that thread you suggested and I see where I can change out WHAT the links say but I am just not sure where the HTML is rendered for them. I looked inside the comments.tpl.php too. I can see some functions that define the values inside the $links array but not where it says to make each one a line item in an unordered list...
Where would I find that?
http://api.drupal.org/api/fun
http://api.drupal.org/api/function/theme_links/6
You check out the devel module and devel_themer. It will tell you what functions are being used to create the output. The universal warning for devel is only turn it on when you need to use it. Don't leave it on all the time.
http://drupal.org/project/devel
http://drupal.org/project/devel_themer
Gil Creque
Here is an example of me
Here is an example of me changing the output to tables. I took the function from the api link I sent you and modified where needed. Most importantly I changed the function name to one that would only effect the theme I'm working in (Garland). If you use Theme developer it will tell you what function names you can use. I then put this new function into my template.php file in my theme directory and flush the theme registry and now my links are in tables rather then unordered lists.
function garland_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<table'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<tr><td'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</td></tr>\n";
}
$output .= '</table>';
}
return $output;
}
Gil Creque
Did that affect all of your
Did that affect all of your links or just the node links (add comment, etc.) I know that the primary links uses this function too. I don't really have a problem with how those are displayed, I am just trying to play with the node links. I looked at the Hook page you linked to and I think you are right, that is more along the lines of what I am looking for. I alsop found a detailed article on the theme_links() function that I am reading at the moment here: http://www.group42.ca/theming_101_the_theme_links_function
Eventually I am going to figure this out.. LOL
Thanks for the sample code. It gives me a better picture of how all this ties together.
Yeah it effects those as
Yeah it effects those as well. The only way I could think of was to check the $links array to see if the key comment_add existed (meaning this is a link for add comment section). I'm not sure if this is the Drupal way, but it works. Another thing I forgot to mention earlier is when making these modifications you should really be using a custom theme or sub-theme. Sample code below.
function garland_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
if (array_key_exists('comment_add', $links))
$output = '<table'. drupal_attributes($attributes) .'>';
else
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
if (array_key_exists('comment_add', $links))
$output .= '<tr><td'. drupal_attributes(array('class' => $class)) .'>';
else
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
if (array_key_exists('comment_add', $links))
$output .= "</td></tr>\n";
else
$output .= "</li>\n";
}
$output .= '</table>';
}
return $output;
}
Gil Creque
What exactly are you trying
What exactly are you trying to do? Change the content of what's displaying or change how it's displaying on the page?
Your original post lists three items that you are trying to change, but the code shows only one item. Are all three of the items appearing on the page now?
(I'm asking these questions so I don't steer you down the wrong path.)
Basically I want to be able
Basically I want to be able to place the links where I want on the page. At some point, I am sure that changing the actual output of the links would be great but for right now, I just want to know how to stuff them in a nice little box. LOL.
The crazy thing is that the theme_links() function is also used for the primary menu (among other things) which means making as custom function a better option for what I want to do. I just want to make sure I understand what I am supposed to do before I jump in and try coding stuff.
To change where they show up
To change where they show up you need to change node.tpl.php or create one for the specific node type (node-nodetype.tpl.php) or just one particular node (node-nodeid.tpl.php). Here I moved the links to show up at the top of the node (based on Garland).
<?php
// $Id: node.tpl.php,v 1.5 2007/10/11 09:51:29 goba Exp $
?>
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php if ($links): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>
<?php print $picture ?>
<?php if ($page == 0): ?>
<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>
<div class="content clear-block">
<?php print $content ?>
</div>
<div class="clear-block">
<div class="meta">
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
</div>
</div>
</div>
Gil Creque
Facepalm
I read that and had a total facepalm moment. Thanks for the code snippet. That turned the lightbulb on for me as far as when the links are called. I am creating a custom node.tpl.php to test my links.