 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
imeridian
Joined: 12 Feb 2002 Posts: 191
|
Posted: Thu Sep 26, 2002 6:46 am Post subject: function b2_references |
|
|
I hope that this may be beneficial to others, b2_references is basically like a reversed trackback, where you can show a link, numerically, to all posts that you've trackbacked on your own site. This is specifically designed to call only internal trackbacks as references.
I use trackback to reference my own posts that are related to one another, which works great when reading older posts, you can move forward, but there's something missing... the link on the current post to the older posts that you've trackbacked.
The call to the function is self contained and is simply:
Code: | <?php b2_references() ?> |
By default it will echo the word "none" when there are no references; however, I have provided a variable to change this, usage as follows:
Code: | <?php b2_references('no references') ?> |
This will, not surprisingly echo "no references" when no refererences exist. Whenever there is a reference (or multiple references) it will echo them as links to the posts each numbered 1+ in order by date, like this:
Code: | <a href="http://yoursite.com/index.php?p=8903">1</a> |
(It's fully compatible with using slashes instead of the normal querystring parameters too)
To get this working, other than including the function call within your b2 loop, you need to add the function to your b2-include/b2template.functions.php file:
The function is as follows:
Code: |
function b2_references($noref='') {
global $tablecomments,$row,$id,$blogfilename,$querystring_start,$querystring_equal,$siteurl;
$requestref = "SELECT comment_post_id FROM $tablecomments WHERE comment_author_url LIKE '%$siteurl%$id'";
$requestref = mysql_query($requestref);
$reference_counter = 0;
if (mysql_num_rows($requestref)){
while($row=mysql_fetch_object($requestref)) {
$reference_counter++;
echo '<a href="/'.$blogfilename.$querystring_start.'p'.$querystring_equal.$row->comment_post_id.'">';
echo "$reference_counter";
echo '</a> ';
}
} else {
if ($noref=='') {
echo 'none';
} else {
echo "$noref";
}
}
}
|
You can see this in action at http://indiboi.com
If you have any problems, questions, find this useful, or have suggestions please let me know. |
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Sun Nov 10, 2002 6:47 am Post subject: b2_backtracks.php |
|
|
All hail imeridian for a cool idea... this might be a slight improvement. Feel free to ignore it if you will.
Code: | <?php
// based off b2_references() by imeridian@http://indiboi.com and the b2 base code
// these keep the same ideas while making the functions behave a bit more like the standard b2 functions
// I can't think of a way to really improve the performance of this without separating the structure
// of the trackbacks from that of a comment. That's more work than it's worth and it wouldn't be future-safe.
// these are table scan db calls - that sucks to say the least. do NOT use this on a high traffic blog.
// I called 'em backtracks cuz thats a reversed trackback (which was a reversed backtrack to begin with)
function backtracks_number( $zero='no BackTracks', $one='1 BackTrack', $more='% BackTracks' ) {
global $siteurl, $tablecomments, $id, $querycount, $cache_bt_number, $use_cache;
if (empty($cache_bt_number[$post_id]) || (!$use_cache)) {
// this query sucks - changes to avoid false postives are directly proportional
// to the decreased execution speed of additional test cases
$query = "SELECT COUNT(*) AS cnt_bt FROM $tablecomments WHERE comment_author_url LIKE '%$siteurl%$id'";
$result = mysql_query($query) or die('SQL query: '.$query.'<br />MySQL Error: '.mysql_error());
$querycount++;
$myrow = mysql_fetch_assoc($result);
$cache_bt_number[$post_id] = $myrow['cnt_bt'];
}
$number = $cache_bt_number[$post_id];
if ($number == 0) {
$blah = $zero;
} elseif ($number == 1) {
$blah = $one;
} elseif ($number > 1) {
$n = $number;
$more=str_replace('%', $n, $more);
$blah = $more;
}
echo $blah;
}
// and as much as I'd like to, I can't make assumptions about the order in which these functions are called.
// unlike the standard b2 functions, and much like b2_references, we output a full series of hyperlinks from this
// maybe in v1.0 of b2, we'll be able to do loops inside each blog entry and this could be normalized further
function backtracks_links() {
global $tablecomments,$id,$blogfilename,$querystring_start,$querystring_equal,$siteurl, $querycount;
$query = "SELECT comment_post_id FROM $tablecomments WHERE comment_author_url LIKE '%$siteurl%$id'";
$result = mysql_query($query) or die('SQL query: '.$query.'<br />MySQL Error: '.mysql_error());
$querycount++;
$reference_counter = 0;
if (mysql_num_rows($result)){
while($row=mysql_fetch_assoc($result)) {
$reference_counter++;
echo ' <a href="'.$siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal.$row['comment_post_id'].'">'.$reference_counter.'</a>';
}
}
}
?> |
|
|
Back to top |
|
 |
Mister44

Joined: 31 Oct 2002 Posts: 237 Location: Philadelphia, PA, USA
|
Posted: Sun Nov 10, 2002 7:32 am Post subject: |
|
|
of course as soon as I post it, I find a bug in it. In backtracks_number(), replace the references to $post_id with $id.
Sorry about that. |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Nov 10, 2002 12:43 pm Post subject: |
|
|
erm is this something like related stories? _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
imeridian
Joined: 12 Feb 2002 Posts: 191
|
Posted: Sun Nov 10, 2002 12:51 pm Post subject: |
|
|
My original function, references, is just that, a way to reference posts in the past from the current entry.
If you trackback an older entry, that older entry will show an excerpt of the new one and a link -> forward -> to the new entry, but without the reference function you'd have no way of knowing by looking at the current entry that the old entry is related; thus this connects entries both forward and backward.
The reason I didn't call this backtrack or trackforward (which is the most logical name I think) is because there's already a 'trackforward' type thing with MovableType (I think it's just a module at this point), and it doesn't really do the same thing as this.
This was pretty much the first b2 function I've ever written, it definitely could stand some improvement, but for me it works, and that's really all I care about most of the time.
Here's an entry with references: http://imeridian.co.uk/history/p/2886631 _________________ -indi<br>
http://indiboi.com
http://artlikepornstars.com
http://www.positivefusion.com |
|
Back to top |
|
 |
GamerZ
Joined: 15 May 2002 Posts: 537 Location: Singapore
|
Posted: Sun Nov 10, 2002 2:26 pm Post subject: |
|
|
hmm interesting, care to make a function for related stories? LOL _________________
++ GamerZ.Per.Sg - Complex Simplicity |
|
Back to top |
|
 |
imeridian
Joined: 12 Feb 2002 Posts: 191
|
Posted: Sun Nov 10, 2002 2:32 pm Post subject: |
|
|
This could be used for that... but I guess if you didn't want to use the trackback method built into b2 you could go through the work of adding a "related entries" field to the forms and database, etc... but since the function is the same I don't really see the need to replicate it.
Though, I just realized that I broke my references function on my site when I changed my siteurl variable in b2config, oops! _________________ -indi<br>
http://indiboi.com
http://artlikepornstars.com
http://www.positivefusion.com |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2 © 2001, 2002 phpBB Group
|