Recent Recs Block?
 
Notifications
Clear all

Recent Recs Block?

9 Posts
3 Users
0 Reactions
1,908 Views
(@michelle)
Posts: 106
Estimable Member
Topic starter
 

I'd love to show off recent recs on the front page. Unfortunately, I'm illiterate when it comes to SQL. I looked at the recent block and tried to work off that. I even got my new block initiated, but I'm stuck on the right SQL query. I should have known it wouldn't be as easy as exchanging "stories" for "recs". LOL.

What I have is:

$result5 = dbquery(_RECQUERY." ORDER BY rec.date DESC LIMIT $numupdated");

But with this, I end up with an error. Any ideas? I'd be thankful for pointers! Especially "pointers for dummies":)


 
Posted : 27/11/2010 6:14 pm
(@lyndsie)
Posts: 1263
Member Moderator
 

You'll have to write out the entire query. I'm guessing _RECQUERY used to be _STORYQUERY, which is actually just code that points to the story query (since it's used so often).

Something like...


<?php
if(!defined("_CHARSET")) exit( );
$count = 0;
$content = "";
$use_tpl = isset($blocks['rec']['tpl']) && $blocks['rec']['tpl'] ? true : false;
if(isset($blocks['rec']['num'])) $numupdated = $blocks['rec']['num'];
else $numupdated = 1;
$result5 = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_recommendations WHERE validated > 0 ORDER BY date DESC LIMIT $numupdated");
while($recs = dbassoc($result5))
{
if(!isset($blocks['rec']['allowtags'])) $recs['summary'] = strip_tags($recs['summary']);
$recs['summary'] = truncate_text(stripslashes($recs['summary']), (!empty($blocks['rec']['sumlength']) ? $blocks['rec']['sumlength'] : 75));
if(!$use_tpl) $content .= "<div class='recentrec'>".title_link($recs)." <br />".stripslashes($recss['summary'])."</div>";
else {
$tpl->newBlock("recblock");
                        // not sure the next line is necessary
include(_BASEDIR."includes/storyblock.php");
}

}
if($use_tpl && dbnumrows($result5) >0) $tpl->gotoBlock("_ROOT");
unset($updated, $result5);
?>

Totally untested. Keep in mind you'll have to edit some of the other files as well, most especially to add {rec_title} and {rec_content} to skins.


 
Posted : 27/11/2010 7:30 pm
(@michelle)
Posts: 106
Estimable Member
Topic starter
 

Oh, this is definitely more progress than I managed to make in one week:)

I'm getting the block to display (not pretty, but that's not a so important at this stage, naturally). But there's a glitch somewhere, probably because the script is taking a wrong turn. It's assuming it should link to something on *my* domain. But the recs are elsewhere, of course. So, it displays the right title and author, but links to an empty story *scratches head*.


 
Posted : 28/11/2010 3:36 pm
(@lyndsie)
Posts: 1263
Member Moderator
 

First, there's a typo:


if(!$use_tpl) $content .= "<div class='recentrec'>".title_link($recs)." <br />".stripslashes($recss['summary'])."</div>";

Should be:


if(!$use_tpl) $content .= "<div class='recentrec'>".title_link($recs)." <br />".stripslashes($recs['summary'])."</div>";

Can I see it on your site? Without knowing what it's doing, it's hard to fix it. I'm guessing it's the way the link's being built, which is different with stories than with recs.


 
Posted : 28/11/2010 7:13 pm
(@tammy)
Posts: 2577
Member Moderator
 

You don't want to use title_link.  That's for stories on site.  You need to build the link url there using the data in $recs.


 
Posted : 29/11/2010 11:05 am
(@michelle)
Posts: 106
Estimable Member
Topic starter
 

I've played around with title_link, because I thought that was the problem, but I haven't gotten it to work yet.


 
Posted : 29/11/2010 3:32 pm
(@lyndsie)
Posts: 1263
Member Moderator
 

Like I said, without seeing it working I can't be sure what's happening. (My test site isn't really working right now.)

Something like...


<?php
if(!defined("_CHARSET")) exit( );
$count = 0;
$content = "";
$use_tpl = isset($blocks['rec']['tpl']) && $blocks['rec']['tpl'] ? true : false;
if(isset($blocks['rec']['num'])) $numupdated = $blocks['rec']['num'];
else $numupdated = 1;
$result5 = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_recommendations WHERE validated > 0 ORDER BY date DESC LIMIT $numupdated");
while($recs = dbassoc($result5))
{
if(!isset($blocks['rec']['allowtags'])) $recs['summary'] = strip_tags($recs['summary']);
$recs['summary'] = truncate_text(stripslashes($recs['summary']), (!empty($blocks['rec']['sumlength']) ? $blocks['rec']['sumlength'] : 75));
if(!$use_tpl) $content .= "<div class='recentrec'><a href=""".$recs['url'"]."">". stripslashes($recs['title']) ."</a><br />".stripslashes($recs['summary'])."</div>";
else {
$tpl->newBlock("recblock");
                       // not sure the next line is necessary
include(_BASEDIR."includes/storyblock.php");
}

}
if($use_tpl && dbnumrows($result5) >0) $tpl->gotoBlock("_ROOT");
unset($updated, $result5);
?>

 
Posted : 29/11/2010 11:06 pm
(@michelle)
Posts: 106
Estimable Member
Topic starter
 

Wohoo! This is working, thank you so much! Looks good so far:) With a bit of copy and pasting, I managed to get the reccer's name in there as well:

<?php
if(!defined("_CHARSET")) exit( );
$count = 0;
$content = "";
$use_tpl = isset($blocks['rec']['tpl']) && $blocks['rec']['tpl'] ? true : false;
if(isset($blocks['rec']['num'])) $numupdated = $blocks['rec']['num'];
else $numupdated = 1;
$result5 = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_recommendations WHERE validated > 0 ORDER BY date DESC LIMIT $numupdated");
while($recs = dbassoc($result5))
{
if(!isset($blocks['rec']['allowtags'])) $recs['summary'] = strip_tags($recs['summary']);
$recs['summary'] = truncate_text(stripslashes($recs['summary']), (!empty($blocks['rec']['sumlength']) ? $blocks['rec']['sumlength'] : 75));
if(!$use_tpl) $content .= "<div class='recentrec'><a href=""".$recs['url'"]."">". stripslashes($recs['title']) ."</a> "._BY." <a href="'"._BASEDIR."viewuser.php?uid=".$recs['uid'"]."'>".stripslashes($recs['recname'])."</a><br />".stripslashes($recs['summary'])."</div>";
else {
$tpl->newBlock("recblock");
                        // not sure the next line is necessary
include(_BASEDIR."includes/storyblock.php");
}

}
if($use_tpl && dbnumrows($result5) >0) $tpl->gotoBlock("_ROOT");
unset($updated, $result5);
?>

 
Posted : 07/12/2010 4:46 pm
(@tammy)
Posts: 2577
Member Moderator
 

You probably want to change


include(_BASEDIR."includes/storyblock.php");

to


include(_BASEDIR."modules/recommendations/recsblock.php");


 
Posted : 09/12/2010 1:08 pm
Share: