scriptygoddess

14 Oct, 2002

Individual Entry and Trackback

Posted by: kristine In: MT hacks

A lot of people using Skins on their blogs want all of the elements of their journal site to have skins on them. This made a lot of people use Individual Archives as popups so that they could be skinned, too. Unfortunately, with the advent of Trackback in MT2.2, there wasn't a good work-around to skin that window because only the trackback listing template and index template were updated upon receiving a ping. And rebuilding every time a ping comes in is a bit tedious of an option, so a lot of people just went with the trackback popups even though it couldn't be skinned.

For people using the MySQL backend and PHP for their files, there is an option now!

Objective – Add auto-updating incoming trackback pings to the Individual Archive, which can be used as a popup for skinning purposes or just for organizing all of the info about a single post into a single screen instead of multiple popups as the default.

Required – Individual Archives with PHP extensions, the MySQL backend and at least MT2.2; setup of a connect.php file as described in the first section of the MySQL authors post. Include that connect file in the top of your Individual Archive template.

This code will set up a header that has the count of trackbacks, followed by the link and excerpt of each trackback received, and then the Trackback URL that can be used to ping:

<MTEntryIfAllowPings>
<?
$blogid = "2";
//replace this with the blog_id of your blog

$entry_id = "<$MTEntryID$>";

$pingcount = mysql_query("SELECT p.tbping_blog_id, t.trackback_entry_id FROM mt_tbping p, mt_trackback t WHERE (p.tbping_blog_id = $blogid) and (t.trackback_entry_id = $entry_id) and (t.trackback_id = p.tbping_tb_id)");
$count = mysql_num_rows($pingcount);

echo "<a name=\"pings\"></a>";
echo "<div class=\"bloghead\">Trackbacks on this post: ", $count, "</div>";

$pingarray = "SELECT p.tbping_source_url, p.tbping_blog_name, p.tbping_created_on, p.tbping_excerpt, p.tbping_tb_id, t.trackback_id, t.trackback_entry_id FROM mt_tbping p, mt_trackback t WHERE (p.tbping_blog_id = $blogid) and (t.trackback_entry_id = $entry_id) and (t.trackback_id = p.tbping_tb_id)";

$resultping = mysql_query($pingarray) or die (mysql_error());

while ($row = mysql_fetch_array($resultping)) {

//set up the variables being used – the date can be configured below

$url = ($row['tbping_source_url']);
$blog = ($row['tbping_blog_name']);
$date = date("F d, Y h:i", strtotime($row['tbping_created_on']));
$excerpt = ($row['tbping_excerpt']);

echo "<div class=\"blogbody\"><p>", $excerpt, "</p></div>";
echo "<div class=\"blogfoot\">Posted by ";
echo "<a href=\"", $url, "\" target=\"_blank\">", $blog, "</a>";
echo "    <i>", $date, "</i></div>";
}
?>
<span class="subhead">Ping this post</span><br /><br />
<div class="code"><$MTEntryTrackbackLink$></div>
</MTEntryIfAllowPings>

With the advent of MT2.5, you can also add a section to display the outgoing pings. I was originally doing it with this code, which will work in MT2.2+:

<?
$entry_id = "<$MTEntryID$>";
$outpings = mysql_query("SELECT entry_pinged_urls FROM mt_entry WHERE $entry_id = entry_id and entry_pinged_urls !=\"\"");
while ($rowout = mysql_fetch_array($outpings)) {
echo "<a name=\"outpings\"></a>";
echo "<div style=\"font-weight:bold; text-align:center;\">URLs Pinged:</div>";
echo "<div class=\"code\">", ($rowout['entry_pinged_urls']), "</div>";
}
?>

But now with MT2.5, there's a tag for this:

<a name="outpings"></a>
<div style="font-weight:bold; text-align:center;">URLs Pinged:</div>
<div class="code"><MTPingsSent>
<$MTPingsSentURL$><br />
</MTPingsSent></div>

I set up a name sections for each of these, so I could have navigation on the top of each Individual Archive template like this:

<div align="center"><a href="#comments">comments</a> | <a href="#pings">incoming pings</a> | <a href="#outpings">outgoing pings</a></div>

Customization notes: I used my div class names in the above examples – you may want to tweak the styles to your liking and put your own class names into it – bloghead is what my date is in, blogbody is the post, blogfoot is the bottom line with posted info, subhead is my subject line. And I have a code class that has added padding and shows in Courier New so that the text looks more like code.

18 Responses to "Individual Entry and Trackback"

1 | Jennifer

October 14th, 2002 at 5:11 pm

Avatar

Neat! Thanks for posting that. 😀

2 | ste

October 14th, 2002 at 6:14 pm

Avatar

Hehe, I always just included the trackback CGI into the individual entry archives using the PHP include directive. :) It's always worked for me …

3 | kristine

October 14th, 2002 at 8:34 pm

Avatar

Ste – I worried about including a cgi file because I don't know much about it and whether or not its risky or not! So yeah, that's why I went this route :)

Since someone on the forums asked another similar question to this this afternoon, I'm posting it to – if you want a count of how many pings you sent, you could use this:

<?
//use this in the context of a MTEntries container or in an Individual Archive template
$entry_id = "<$MTEntryID$>";

$pingsent = mysql_query("SELECT entry_pinged_urls FROM mt_entry WHERE $entry_id = entry_id and entry_pinged_urls !=\"\"");
$pingsentcount = mysql_num_rows($pingsent);
echo $pingsentcount;
?>

:)

4 | kristine

November 3rd, 2002 at 9:12 pm

Avatar

Kymberlie pointed out that my count of how many pings sent wasn't working quite right – and Eric (husband!) helped me debug it this afternoon – Here's some better code :)

<?
$pingsent = "SELECT entry_pinged_urls FROM mt_entry WHERE $entry_id = entry_id and entry_pinged_urls !=\"\"";
$pingsentcountresult = mysql_query($pingsent) or die (mysql_error());
$pingsentcountarray = mysql_fetch_row($pingsentcountresult);
$pingsentcounts=explode("\n", $pingsentcountarray[0]);
if (!is_array($pingsentcountarray)) { echo "No URLs Pinged"; }
else {
$pingsentcount = count($pingsentcounts);
if ($pingsentcount=="1") { echo $pingsentcount, " URL Pinged:";}
else {echo "URLs Pinged: ", $pingsentcount;}
}
?>

5 | Lisa, Gal of Unix

February 8th, 2003 at 12:44 pm

Avatar

Thanks for the tip, Kristine!

6 | RobN

September 13th, 2003 at 12:19 am

Avatar

Muchas gracias, Kristine, for sending me down the right road. I started out with your script examples, hacked them a bit to get what I was looking for, and integrated it all seamlessly with my site's individual archive layout.

The concept is wonderful, and it doesn't require the delay or risk of an entry rebuild. The sad thing is that, to be honest, I hadn't thought of embedding the Perl code to perform this function in the page itself. I was looking for ways to hack the mt-tb.cgi module to rebuild the entry_ID upon receipt of a TB ping. Of course, I imagine that would be a heck of a DOS target with the higher overhead of the .cgi call.

7 | Blinger

February 25th, 2004 at 7:39 am

Avatar

I'm confused as to where I should place the php include. At the top of the individual archive but where? between the head tags, before the head tags, in the body?

8 | Blinger

February 25th, 2004 at 7:40 am

Avatar

I'm confused as to where I should place the php include. At the top of the individual archive but where? between the head tags, before the head tags, in the body?

9 | kadyellebee

October 14th, 2002 at 4:02 pm

Avatar

Individual Entries
Do you like how my Individual Archives are set up with the incoming and outgoing pings? I wrote a tutorial

10 | Ain't too proud to blog

October 17th, 2002 at 9:59 pm

Avatar

Once more with feeling
Small addition made to my comment / individual archives templates thanks to the Scripty Goddesses. In addition to the pop-up with the URLs that have pinged me, now you can also view the sites I've pinged for each entry as well. For example, here are th…

11 | Neurotic Fishbowl

October 23rd, 2002 at 2:15 pm

Avatar

To Do List 102102
It's been like a month since I've done a To Do List, but I did manage to eliminate a few

12 | Neurotic Fishbowl

October 23rd, 2002 at 10:49 pm

Avatar

MT hacks: Individual Entry and Trackback
After much mucking about, my individual archives now reflect trackbacks both sent and received like Kristine and Robyn's sites do.

13 | kadyellebee

December 11th, 2002 at 11:12 pm

Avatar

Trackback sixlog-style
I saw yesterday on Mena's blog that her and Ben were going to start blogging general technology things at their

14 | Girlie's Tips and Tricks

January 19th, 2003 at 2:18 pm

Avatar

individual entry trackbacks
Pull trackback info directly from the MySQL database, courtesy of Kristine.

15 | Life, the Universe, and Me

September 13th, 2003 at 12:21 am

Avatar

Trackback and Dynamic Pages
Now, whenever an entry with TrackBack pings is loaded, it dynamically pulls its associated data from the database and includes it in the page. Just like a comment. Suh-weet!

16 | Phil Gyford

January 14th, 2004 at 11:47 am

Avatar

Pepys TrackBack: fixing the problems and a new layout
I had to write some tools to manage the duplicated TrackBacks at Pepys' Diary, but it meant I could then create a whole new (un-TrackBack-like) layout for the TrackBack listings.

17 | LilacRose

March 22nd, 2004 at 9:51 pm

Avatar

Site Tweaks
I wanted to add inline trackbacks in my individual entries, but I didn't want to have to rebuild an entry…

18 | Glimpse of a Grrl

May 23rd, 2004 at 10:20 pm

Avatar

Randoms
– cleaned up the Buell skin – looked up photographers from desktop archive and found URLs for most of them – added "outbound pings" to individual entries (and moved pings below comments) [info found at Scripty Goddess – scroll to…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements