boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Hacks] Related Stories
Goto page 1, 2  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Tue Dec 10, 2002 8:42 am    Post subject: [Hacks] Related Stories Reply with quote

I have created a related stories feature that will automatic such the headlines and display 5 related stories(default).

Copy the function and put it inside b2template.functions.php

If you want to exclude some search word, just add it in the $exclude array.

To use it just use [php:1:388f58132d]<?php relatedstories(); ?>[/php:1:388f58132d] outside b2 loop.


If you want 10 related stories just add in 10 which becomes[php:1:388f58132d]<?php relatedstories(10); ?>[/php:1:388f58132d]

Here is the function:
[php:1:388f58132d]
function relatedstories($howmanystories=5) {
global $tableposts, $siteurl,$blogfilename, $id, $querystring_start, $querystring_equal, $querystring_separator;
$titlesearch = get_the_title();
$exclude = array ("A", "Are", "Do", "It", "Its", "Is", "In", "I", "My", "The", "To", "With", "You");
$qry = "SELECT DISTINCT ID, DATE_FORMAT(post_date, '%e/%c/%y'), post_content, post_title FROM $tableposts WHERE (";
$titlesearch = preg_replace('/, +/', '', $titlesearch);
$titlesearch = trim($titlesearch);
$words = explode (" ", $titlesearch);
$words = array_diff($words,$exclude);
foreach ($words as $word) {
$qry .= "(post_content LIKE '%$word%' OR post_title LIKE '%$word%') OR ";
}
$qry = substr ($qry, 0, strlen ($qry) - 4);
$qry .= ") AND (ID != $id) ORDER BY post_date DESC LIMIT $howmanystories";
$sql = mysql_query($qry);
while ($relatedstories = mysql_fetch_row($sql)) {
echo "<b>»</b> <a href=\"".$siteurl."/".$blogfilename.$querystring_start."p".$querystring_equal.$relatedstories[0].$querystring_separator."c".$querystring_equal."1\">";
echo stripslashes($relatedstories[3]) ."</a>";
echo " (".$relatedstories[1].")";
echo "<br>";
}
}
[/php:1:388f58132d]
_________________

++ GamerZ.Per.Sg - Complex Simplicity


Last edited by GamerZ on Sun Jan 05, 2003 4:40 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
turtelina



Joined: 25 Jan 2002
Posts: 35
Location: Austria

PostPosted: Tue Dec 10, 2002 10:29 pm    Post subject: Reply with quote

Hi Gamerz,

I installed it. It´s awesome!!! Thank you so much for sharing it!

Back to top
View user's profile Send private message Visit poster's website
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Wed Dec 11, 2002 7:15 am    Post subject: Reply with quote

turtelina wrote:
Hi Gamerz,

I installed it. It´s awesome!!! Thank you so much for sharing it!

NP glad you like it
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
JEDOK



Joined: 19 Dec 2002
Posts: 4
Location: korea

PostPosted: Thu Dec 19, 2002 4:59 am    Post subject: Reply with quote

it's a nice idea and works fine. but, there is just one bug.

if the title is consisted of the excluded words(words in $exclude array) only, the error occur

example: when i put "I", "love", "you" in $exclude array and write a post titled "I love you", then,

Quote:
Warning: Supplied argument is not a valid MySQL result resource in /home/u2ii/public_html/b2test/b2-include/b2template.functions.php on line 1217


i hope someone can fix this. and will it be possible to make it search through only the titles(not the whole "content" of the posts)?
Back to top
View user's profile Send private message Visit poster's website
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Thu Dec 19, 2002 3:21 pm    Post subject: Reply with quote

JEDOK wrote:
it's a nice idea and works fine. but, there is just one bug.

if the title is consisted of the excluded words(words in $exclude array) only, the error occur

example: when i put "I", "love", "you" in $exclude array and write a post titled "I love you", then,

Quote:
Warning: Supplied argument is not a valid MySQL result resource in /home/u2ii/public_html/b2test/b2-include/b2template.functions.php on line 1217


i hope someone can fix this. and will it be possible to make it search through only the titles(not the whole "content" of the posts)?
good bug there, but normally I dun think anyone will use all excluded word in the title?

for the title only replace with this[php:1:fb41819051]$qry .= "(post_title LIKE '%$word%') OR ";[/php:1:fb41819051]
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1075
Location: Oregon

PostPosted: Sat Jan 04, 2003 6:54 pm    Post subject: Reply with quote

I don't understand the concept of this hack. Related stories of what?
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
BDKR



Joined: 04 Jan 2003
Posts: 20
Location: Venezuela

PostPosted: Sat Jan 04, 2003 11:00 pm    Post subject: Reply with quote

Cool hack!
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
dtdgoomba



Joined: 05 Aug 2002
Posts: 179
Location: Cambridge, MA

PostPosted: Sun Jan 05, 2003 2:11 am    Post subject: Reply with quote

i think the hack finds stories within your site that are 'related' to your current post by finding similar phrases/words in other posts? Is that it?
Back to top
View user's profile Send private message Visit poster's website
Cyberian75



Joined: 26 Sep 2002
Posts: 1075
Location: Oregon

PostPosted: Sun Jan 05, 2003 2:19 am    Post subject: Reply with quote

Oh, I guess it uses the latest post. Yeah? What a great idea . . . Smile
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Sun Jan 05, 2003 7:49 am    Post subject: Reply with quote

it just seacrh thru the DB for content or title tt matches the current blog subject and displays it in order of date.

You can exclude some words tt dun want to be searched
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
annia



Joined: 09 Apr 2002
Posts: 18

PostPosted: Sun Jan 05, 2003 8:58 pm    Post subject: Reply with quote

i love that hack :) it works good for me
Back to top
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1075
Location: Oregon

PostPosted: Tue Jan 07, 2003 11:52 pm    Post subject: Reply with quote

I get . . .

Quote:

mysql_fetch_row(): supplied argument is not a valid MySQL result resource


Can you fix this?
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Wed Jan 08, 2003 5:11 am    Post subject: Reply with quote

Cyberian75 wrote:
I get . . .

Quote:

mysql_fetch_row(): supplied argument is not a valid MySQL result resource


Can you fix this?
at line?
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Cyberian75



Joined: 26 Sep 2002
Posts: 1075
Location: Oregon

PostPosted: Wed Jan 08, 2003 5:15 am    Post subject: Reply with quote

At line 17 of your function...
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Wed Jan 08, 2003 11:21 am    Post subject: Reply with quote

Cyberian75 wrote:
At line 17 of your function...
wierd, but it seems okie to me?
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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