Hi all,

I'd like to theme the blog_link function in blog.module to
change the way my links are displayed. After a bit of research it seems
that I've to change the function itself to achive this effect. I don't like this
solution.

However it occured to me that maybe it could be done by overwriting an
hipothetical theme_blog_link function in phptemplate (that same way we theme users' profiles).

So if I create a theme_blog_link in the blog.module (and I re-write the blog_link
function in terms of theme_blog_link) would it be possible to use the same technique ?

I tried, but I think I've missed something ...

thanks !

Comments

kingandy’s picture

Two years later there still doesn't seem to be any kind of customisation possible for this in core, and IMO it's a crippling oversight on the part of the blog module. However, different approaches are needed for 4.7 and 5.x due to the changes in hook_link.

--- 4.7.x ---

The most likely reason this didn't work in 2006 is that without the blog_link function, the system simply isn't aware that there's a link to be added. What you needed to do was a hook_link implementation that then called a separate (overrideable) theme_blog_link function. Something like this:

/**
 * Implementation of hook_link().
 */
function blog_link($type, $node = 0, $main = 0) {
  $links = array();

  if ($type == 'node' && $node->type == 'blog') {
    if (arg(0) != 'blog' || arg(1) != $node->uid) {
      $links[] = theme('blog_link', $node);
    }
  }

  return $links;
}

function theme_blog_link($node) {
  l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
}

theme_blog_link could then be overridden with a phptemplate_blog_link() function.

--- 5.x onwards ---

Instead of taking an array of pre-rendered links here, the new hook_link returns an array of link arrays (which is to say, arrays with 'title' and 'href' indexed elements, along with the usual optionals like 'attributes', 'query', etc). On the plus side, this makes it a lot easier for themers to sort through the link arrays as they are, with a phptemplate_links() function:

function phptemplate_links($links, $attributes = array('class' => 'links')) {
  foreach($links as $key => $link) {
    if (substr($link['href'], 0, 4) == 'blog') {
      ...
    }
  }
  return theme_links($links, $attributes);
}

Inside the clause you could either reset the link's title ($link['title'] = t('More by the same author'); or whatever), or remove the link altogether (unset($links[$key]);).

--Andy
Developing Drupal websites for Livelink New Media

++Andy

graper’s picture

after the code it is suggested to use $link['title'] =t('blah'); this didn't work. I have to use the following to actually affect the true link, not sure why $link didn't refer back properly.

$links[$key]['title']="blah";
kingandy’s picture

That's a basic mistake on my part - I forgot that when you're inside a foreach($a as $k => $v) loop, the $v is actually a copy of $a[$k], and not a direct reference. In my defense I did say "or whatever" and seem to have remembered for the "unset($links[$key])" below :-)

++Andy