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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 561
  • Total: 561

custom "Recent Topics from Board X, Y, Z only" php block

Started by iowamf, November 04, 2005, 09:47:16 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

snoopy_inc

So if i copy his quoted code i wont have trouble?  It can disply multiple boards new posts right? not just a singular board?

jacortina

Use the code I posted in the 'code' boxes in message:
http://www.tinyportal.net/index.php?topic=1234.msg105411#msg105411

As noted, the first part should be added to the SSI.php file (defines a new SSI function).

Then you put the second part in a block. The one line to pay attention to there (and you'll want to change) is:

$result=ssi_recentTopics_Include(10,array(9),'return');

That '10' is the number of topics to return.

That 'array(9)' is the list of boards to get recent topics from. So, you can change it to, for intance, 'array(5,6,10,18)' to get from board numbers 5, 6, 10, and 18.


jakemelon

Hi,

I got this to work, looks good! How can you add more details about the recent posts such as:

1) *NEW* icon next to each new post (if posted today)
2) name of forum where the post was made
3) name of person who wrote post
4) if posted today display "Posted TODAY", if yesterday display YESTERDAY, if older then yesterday display "posted x days ago"


I know I am asking for alot! hehehe

thanks!

jake

jacortina

Quote from: jakemelon on February 11, 2007, 03:50:56 PM
Hi,

I got this to work, looks good! How can you add more details about the recent posts such as:

1) *NEW* icon next to each new post (if posted today)
2) name of forum where the post was made
3) name of person who wrote post
4) if posted today display "Posted TODAY", if yesterday display YESTERDAY, if older then yesterday display "posted x days ago"


I know I am asking for alot! hehehe

thanks!

jake

You can only make use of the information passed back in the array. To check what that information is, look at the function that is added to SSI. You'll see the array is:
$posts[] = array(
'board' => array(
'id' => $row['ID_BOARD'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => $row['ID_TOPIC'],
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',



1) Note that *NEW* icon denotes unread in SMF and not posted today. Also, that icon also should be a link to the first unread post in the topic. Given the usage up-thread (foreach($result as $my)), this should put out the new icon as a link to first unread in topic:
if ($my['new'] == 0)
echo '<a href="', $scripturl . '?topic=' . $my['topic'] . '.msg' . $my['new_from'] . ';topicseen#new'"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" /></a>';


2) Board name would be in $my['board']['name']

3) Name of most recent poster would be in $my['poster']['name']

4) This would depend on your settings for the forum (for 'Today' and 'Yesterday') and 'X days ago' is not something that's set up anywhere (would just show date). and that would be in $my['time'].

jakemelon

Hi,

Something is not working for me, missing ',' or ';'.

I looked at the original vs the new piece, dont see anything missing.

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/content/j/a/k/jakemelon/html/Sources/Load.php(1733) : eval()'d code(35) : eval()'d code on line 12


jacortina

Well, I'd have to see the code after you made the addition.

Maybe the previous statement wasn't closed prior to the insert 'if'.

jakemelon

Okay I got the ' and ; figured out but the output is not correct. Here is what the box looks like:

Recent Topics
I am new test topic
Welcome!
Welcome to SMF!

It does not show name of poster for some reason even tho it is in the code below, it only show the topic header....I am really new to this (as you can see), I really appreciate your help and patience!


Quoteglobal $context, $scripturl;
$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';

$result=ssi_recentTopics_Include(10,array(1,2),'return');

foreach($result as $my){
  echo "$bullet";
  echo '<span class="smalltext">'.$my['link'];
echo '
';
  // is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '<a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], $my['poster']['name'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';
echo '
';
}
echo '</span>';

jacortina

That's because you embedded it within the link (within the <a href which doesn't end until after the #new)

Also, what version of SMF are you running. I didn't think that 'from' construction you have there for the 'new' was used in the 1.1 series.

Try this:
global $context, $scripturl, $settings, $txt;
$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';

$result=ssi_recentTopics_Include(10,array(1,2),'return');

foreach($result as $my){
  echo "$bullet";
  echo '<span class="smalltext">'.$my['link'];

  // is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
        echo ' <a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['new_from'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';
echo ' in ', $my['board']['link'];
echo ' by ', $my['poster']['link'];
echo ' posted ', $my['time'];
echo '<br />';

}
echo '</span>';


You can pull out/rearrange the other fields tacked on there (board name as link to board, poster name as link to profile, and time posted).

jakemelon

Alright this works like a charm! I am using 1.1.1 but I think original snipped I copied from the forum must have been older. I was able to make some tweaks to this now and it is perfect!

thank you!
jake

This website is proudly hosted on Crocweb Cloud Website Hosting.