TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,022
  • Total Topics: 21,332
  • Online today: 473
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 147
  • Total: 148
  • @rjen

Custom Recent Topics block.[2nd Update!]

Started by Megaforum, July 26, 2007, 11:59:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dragooon

Hello, Your old noob is back :P
But this time I am not asking something.I was roaming around TP forums and found quite a few requests about this block so decided to make it.
It can :
- Show topic name and link
- Show some body part of it(can be customized on how much you want to show).
- Show where the topic is posted.
- Can be customized on how many topics you want to show.
- Can be made so that it shows topics from only 1 specified boards.
Updated!
- Now fixed the user group error.Now they will see what they can see.
Update No. 2!
- Now fixed the code so that it doesent shows topics from a recycle thread board

Main source code to be entered in a Center php block(Using left or right will mess it up) :
//Custom Recent posts
//Made by Dragooon
global $scripturl, $db_prefix, $context, $smfFunc, $txt, $user_info, $modSettings;
//Main query
$result = db_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = b.id_board
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{      //The variable which decides the MAX letters it can have.
$bodylen = 200;
// Limit the length of the message, if the option is set.
if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


censorText($row['body']);
censorText($row['subject']);

$context['rp'][] = array(
'title' => $row['subject'],
'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'description' => $row['body'],
'category' =>  $scripturl .'?board=' .$row['id_board'] . '.0',
'bname' => $row['bname']
);
}
foreach( $context['rp'] as $info)
echo'
<dt><br><a href="', $info['link'], '">', $info['title'], '</a></dt>
<dd>', $info['description'], '<br>posted in <a href ="',$info['category'],'">',$info['bname'],'</a></dd>
</dlv>';


This code will show 5 recent posts from any board.Its maximum letter limit would be 200 if crossed it will be "...".

Customization :
To limit the number of topics shown:
See that LIMIT 5 and edit the 5 to no. of posts you want.

To show posts from 1 board.
See that t.id_board = b.id_board.Edit it and change it to t.id_board = <Your Board ID> AND b.id_board = <Your Board ID>
Make the Board ID to match the ID of the board you want to show.Remember BOTH entries must be same.

To limit the length of max body letters which can be shown:
Find $bodylen = 200; and edit 200 with what you want.

Well I hope you like it.

I made it with help of a Post that Thantos made in SMF community

Ken.

Thanks Dragooon this sounds good, we'll have to give it a try.  :)
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

Dragooon


Dragooon

Ok I updated this thing.I fixed the fact that the members or guests were able to see posts from boards which they dont have access to.

Dragooon

Updated again!
Fixed the thing so that it doesent shows topics from a thrash board.

MeRcChRiS

Im getting a Internal Server error when I add this code to a centered php block.

knat

im getting Page Not Found when i add this  :P

Maybe this only works for latest versions of SMF & TP  ::)

Dragooon


celdric

#8
Hi.  :) This sounds like a good mod.  Although have problems with the customizing.

I did it the way below.  31.0 is the board id

I edited
WHERE t.id_board = 31.0 AND b.id_board = 31.0


and

WHERE t.id_board = <31.0> AND b.id_board = <31.0>

Either way it does not work. Well, I suppose that I misunderstand your post. Can you please post an example?  :)

Dragooon

What was the full thing you did?
Can I see the full code you added?

This website is proudly hosted on Crocweb Cloud Website Hosting.