How to theme the trackback URL in Drupal

Just a little detail: do you like the way how the trackback-module displays the trackback-url on your drupal-site? There's a simple way to change this behavior. It requires some little changes in the module-source, but perhaps that will give you an understanding of the programming of drupal-modules...

At first have a look at the trackback.module file, especially on line 261:

$node->body .= theme('box', t('Trackback URL for this post:'), url('trackback/'. $node->nid, NULL, NULL, TRUE));

this line themes the trackback-url. Unfortunately the theme-function "box" is used to do that. The box-function creates an html-code enclosed by <div class="box">. Because there are many occurrences of this class, and it's not only used to theme the trackback-url, you can't style the trackback-url by this class in your CSS-file. To solve this problem, use a new theme-function like this:

$node->body .= theme('trackbackurl', t('Trackback URL for this post:'), url('trackback/'. $node->nid, NULL, NULL, TRUE));

Now, drupal will call the theme-function "trackbackurl" to theme the url. The next step is to create this function. The best place to do this is right here in the trackback.module. Insert the following code at the end of the file:

function theme_trackbackurl ($title, $content, $region = 'main')
{
$output= '';
$output.= $title.''.$content.'';
$output.= '';
return $output;
};

Now you can style your trackback-urls in your CSS-File. Add something like this:

.trackbackurl {
font-weight: bold;
color: #9e4040;
margin-bottom: 20px;
}

.trackbackurl .url {
font-weight: normal;
font-family: mono, courier;
color: black;
padding-left: 20px;
}

Kommentare

In Drupal 5 sieht das Trackback-Module ein wenig anders aus und es funktionert auf die oben beschriebene Art&Weise nicht mehr.

Gruß
Markus

Stelle auch gerade meine Seiten auf Drupal 5.x um. Für das Trackback-Modul habe ich folgenden Code-Snippet für die box.tpl.php verwendet:

<?php if ($title == 'Trackback URL for this post:') { ?>

Trackback url for this post:
" title="trackback">
<?php print $content ?>

<?php } else { ?>

<?php print $title ?>

<?php print $content ?>
<?php } ?>

Einfach in die box.tpl.php des verwendeten Themes einsetzen. Damit sind die Urls klickbar und können nach Belieben formatiert werden. Nicht elegant, aber funktional.

Grüße,
Harry