how do i print trackbacks in a custom template?

thinkinkless - January 16, 2006 - 23:04
Project:TrackBack
Version:4.7.x-1.x-dev
Component:Other
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Question: how do I call the trackback box in a custom (phptemplate) eg: node-flexinode-1.tpl.php?

We use heavy theming on our site and the only module that uses $content to print the node body is blog. As a result the only nodes currently showing trackbacks are blogs.

Thanks in advance.

#1

obscurity - February 5, 2007 - 22:02

This seems to have been asked a number of times without a response so:

I found this suggestion at HiveMinds using a custom module and bits of phptemplate: http://www.hiveminds.co.uk/node/871

And this one which uses CSS: http://www.hoelterhof.net/scb/drupal/trackback

#2

jenlampton - February 28, 2007 - 03:50
Version:4.6.x-1.x-dev» 4.7.x-1.x-dev

I'm having the same problem with 4.7.x. If I enable trackbacks for default content types, I have no problems. The trackback displays at the bottom of the content. But when I try to use them for custom content types (which, it turns out, is the only place i need them on this site) the trackback link is not displayed at all.

I'm guessing this is because the CCK module doesn't use $content to show the content of the page, and the trackback module adds the 'box' with the link into $content. I'm about to try the z_index module method, but I really feel like I'm grasping at straws here... it looks like it was developed for 4.6, and not only am I not aware of any subtle differences between the two versions, but I'm pretty sure even though the rest of the steps are clearly outlined, the module itself isn't included, and I might not be able to find it on the Drupal site, or anywhere else, for that matter.

Has anyone else run into this problem, is there an easier way to fix it? (maybe work with CCK to use $content? or update trackback to use something more universal?)

any help much appreciated!
Jen

#3

eurekaloop - March 16, 2007 - 17:29

I was having trouble with this as well, and decided to go ahead and do a manual pull from the $content string. Here's what I came up with, which isolates just the trackback. Just paste it into your CCK "node-whatever.tpl.php" template file:

<div id="trackbacks">
<?php
$contentlength
= strlen($content);
$position = strpos($content, 'rdf:RDF');
$trackbacks = substr($content, $position-6, -6);
print
$trackbacks;
?>

</div>

By placing it in the "trackbacks" div you can now style it in CSS, too.

#trackbacks .box {
}
#trackbacks .title {
}
#trackbacks .content {
}

It's a little silly, but this way you don't have to mess with the trackback.module code. Luckily, the trackback is the last thing to be included in the $content string (at least on my site). If you have other modules that attach to the $content string after the trackbacks, you may get some redundant content showing up.

#4

eurekaloop - March 16, 2007 - 22:12

Looks like the above line

$trackbacks = substr($content, $position-6, -6);

may need to be changed to

$trackbacks = substr($content, $position-6, -7);

as a random ">" was showing up once trackbacks were received...

#5

eurekaloop - March 21, 2007 - 21:14

Just went to validate and realized I screwed that up...geez!

Try this instead...

<div id="trackbackcode">
<?php
$contentlength
= strlen($content);
$position = strpos($content, 'rdf:RDF');
$trackbacklist = substr($content, $position-6);
print
$trackbacklist; ?>

</div><!--end of trackbackcode div-->

#6

jenlampton - March 28, 2007 - 01:56

ok - so this made the trackback div show up on the pages it was missing from, but now there are now 2 blocks on the pages where it was already displayed... and on the pages where it was missing, there is still no link! I think the problem i that the trackback links are not being created for my custom content types... any ideas?

Jen

#7

jenlampton - March 28, 2007 - 03:14

hold up a minute here people, all this does is take a piece of $content and spit it out into the node.tpl.php? my node.tpl.php already spits out ALL of $content, so forcing it to repeat itself won't make the trackback links show up for me. My problem is that trackbacks are NOT being appended into $content for custom content types. have any of you had my problem or is this something different?

Jen

#8

eurekaloop - April 1, 2007 - 06:53

Jen, try creating a unique tpl file, like node-custom.tpl.php (where "custom" is the type of custom node). You can use the contemplate module to get all of the different variables that you can call for that custom node, and you can insert the trackback code wherever you want it to show up.

#9

eurekaloop - November 19, 2009 - 20:56
Status:active» closed

Old issue - no further responses.

 
 

Drupal is a registered trademark of Dries Buytaert.