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 Previous  1, 2
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Cyberian75



Joined: 26 Sep 2002
Posts: 1084
Location: Oregon

PostPosted: Wed Jan 08, 2003 6:14 pm    Post subject: Reply with quote

oh well...
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Ruud



Joined: 12 Oct 2002
Posts: 77

PostPosted: Mon Apr 28, 2003 1:53 pm    Post subject: Reply with quote

While adding scripts to download @ dawolfden.com I realised this hack will show category zero posts, the so-called private/unpublished category.

To prevent this behaviour find this line

Code:
$qry .= ") AND (ID != $id)  ORDER BY post_date DESC LIMIT $howmanystories";


and change it to:

Code:
$qry .= ") AND (ID != $id) AND (post_category > 0) ORDER BY post_date DESC LIMIT $howmanystories";


The download has been updated with instructions to reflect the initial behaviour and the modification.

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



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Mon Apr 28, 2003 2:50 pm    Post subject: Reply with quote

Oh, thanks for the fix =D
_________________

++ 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
Ruud



Joined: 12 Oct 2002
Posts: 77

PostPosted: Mon Apr 28, 2003 3:59 pm    Post subject: Reply with quote

On dawolfden.com I use a slightly modified version of the related stories hack. You can pass the value of a b2 custom field to it. This way I can ensure that the list of related stories is more or less specific to certain keywords instead of just any word within the title/post. I.e. for this post I would pass it the words 'related custom', for instance.

Info & download here

Full credits to Lester/Gamerz and Mystis.

Ruud


Last edited by Ruud on Thu May 01, 2003 5:49 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Mon Apr 28, 2003 5:34 pm    Post subject: Reply with quote

Ruud wrote:
On dawolfden.com I use a slightly modified version of the related stories hack. You can pass the value of a b2 custom field to it. This way I can ensure that the list of related stories is more or less specific to certain keywords instead of just any word within the title/post. I.e. for this post I would pass it the words 'related custom', for instance.

Info & download here

Full credits to Lester/Gamerz and Mystis.

Ruud
Hehe, okie thanks ^^
_________________

++ 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
blog17



Joined: 28 Jan 2003
Posts: 144
Location: London, UK

PostPosted: Mon Apr 28, 2003 7:02 pm    Post subject: Reply with quote

Ive been looking and it seems that no-one has an example on their pages! Can someone please show me one?

The hack is a great idea! I thought that I came up with it last night, I am surprised to see it here! Excellent.
_________________
Check this out! The ULTIMATE site!
Back to top
View user's profile Send private message Visit poster's website
Ruud



Joined: 12 Oct 2002
Posts: 77

PostPosted: Mon Apr 28, 2003 7:23 pm    Post subject: Reply with quote

On the link provided above you can see a demo of the custom related stories.

Here you can see a demo of Lester/Gamerz original related stories.

All scripts on dawolfden.com have an online demo or at the very least screenshots. So as I'm working my way through the forum I'm testing the scripts, putting them up for download, put a demo online, etc. For info about what I'm doing read here

Ruud


Last edited by Ruud on Thu May 01, 2003 5:50 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
donncha



Joined: 18 Feb 2003
Posts: 43
Location: Cork, Ireland

PostPosted: Mon Apr 28, 2003 8:58 pm    Post subject: excellent hack! Reply with quote

Brilliant bit of code there!
If you don't mind, I've integrated it into b2++ and I'll package it with the next release (with credits in the file of course!)
See an example of it working here:
http://blogs.linux.ie/xeer/archives/p/89490285/c/1

Over the next few days I'll probably make the exclude list configurable through b2options,
and make the list of related articles into a Smarty template so it can be changed through the web browser.

I added a check for mysql_num_rows( $sql ) to avoid situation where no related article was found.
I also modified it so it only displays the list of related stories when you a distinct post, not the main weblog.
Plus a few more things...

If you want to use this hack with the current release of b2++, then edit blog.header.php
and add the following lines at the end of the file: (which enables support for "pre functions")

Code:

if( $dir = @opendir("plugins") )
{
    while ($pluginfile = readdir($dir))
    {   
        if( substr( $pluginfile, 0, 14 ) == 'b2.prefunction' )
        {
            include_once( "plugins/" . $pluginfile );
            $pluginfunc = substr( $pluginfile, 15, -4 );
            $pluginfunc( $smarty );
        }
    }
}


The next release of b2++ will have that in there..
Put the following code into a file called b2.prefunction.relatedstories.php in your plugin directory.

Code:

function relatedstories( &$smarty )
{
    global $p,$tableposts, $siteurl,$blogfilename, $id, $querystring_start, $querystring_equal, $querystring_separator;

    $ret = "";
    if( $p != "" )
    {   
        $qry = "SELECT post_title, post_content FROM $tableposts WHERE ID='$p'";
        $sql = mysql_query($qry);
        if( mysql_num_rows( $sql ) )
        {   
            $t = mysql_fetch_row($sql);
            $titlesearch = $t[0];
            if( $titlesearch == '' )
                $titlesearch = substr( str_replace( "'", "", strip_tags( $t[1] ) ), 0, 20 );

            $howmanystories=5;

            $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 = strtolower( trim($titlesearch) );
            $words = explode (" ", $titlesearch);
            $words = array_diff($words,$exclude);

            reset( $words );
            foreach ($words as $word)
            {
                if( strlen( $word ) > 2 )
                {
                    $qry .= "(post_content LIKE '% $word%' OR post_title LIKE '% $word%') OR ";
                }
            }
            $qry = substr ($qry, 0, strlen ($qry) - 4);
            $qry .= ") AND (ID != $p)  ORDER BY post_date DESC LIMIT $howmanystories";
            $sql = mysql_query($qry);
            if( mysql_num_rows( $sql ) )
            {   
                $ret = "<br><br><div align='left'>Related Stories:<ul>";
                while ($relatedstories = mysql_fetch_row($sql))
                {   
                    $content = substr( stripslashes( htmlspecialchars( strip_tags( $relatedstories[2] ), ENT_QUOTES )),0, 100 ) ."...";
                    if( $relatedstories[3] != '' )
                    {   
                        $title = $relatedstories[3];
                    }
                    else
                    {   
                        $title = substr( $content, 0, 15 ) . "...";
                    }

                    $ret .= "<li> <a href=\"".$siteurl."/".$blogfilename.$querystring_start."p".$querystring_equal.$relatedstories[0].$querystring_separator."c".$querystring_equal."1\" title='".$content."'>";
                    $ret .= $title ."</a>";
                    $ret .= " (".$relatedstories[1].")";
                    $ret .= "</li>\n";
                }
                $ret .= "</ul>\n</div>";
            }
        }
    }

    $smarty->assign( "relatedstories", $ret );
}


And then in your post.tpl, add the Smarty variable {$relatedstories} somewhere,
preferably just below the weblog post. Here's an example from my own blog:
http://blogs.linux.ie/xeer/templates/post.tpl

Thanks again Gamerz for a cool hack Smile

Get b2++ at http://cork.linux.ie/filemgmt/viewcat.php?cid=4

UPDATE! I updated the plugin above and made it prune out any word less
than 3 characters in length. This removes the word "b2" unfortunately, but returns
more relevant posts in general.
I also added a space before the $word variable in the sql, so that a
search for "ping" won't find "shopping".


Last edited by donncha on Tue Apr 29, 2003 10:35 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
GamerZ



Joined: 15 May 2002
Posts: 537
Location: Singapore

PostPosted: Tue Apr 29, 2003 7:01 am    Post subject: Reply with quote

np guys, thats the beauty of open source, we share codes and exchange ideas =D Hehe Smile
_________________

++ 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 Previous  1, 2
Page 2 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