Edit by Freddy : In the first part of this thread you will find code for SMF1. If you want SMF 2 code then that can be found here (http://www.tinyportal.net/index.php?topic=33286)...
Feel free to continue in this thread with discussion. Cheers :)
==========================================
This is a continuation of the request for a block in this topic (http://www.tinyportal.net/index.php/topic,23006.0.html). I've given a few more options and compacted the code.
What it does: Displays the first post from random topics, rather like the "recent topics" functions. It will show topics from all boards that the user can see. You can limit it to one category of boards if you prefer. You can also limit the number of characters to display. You can set the number of posts.
Where to put it: In either a php block or a php article. If you want more than one topic to display, it would probably be best to put it into an article.
global $db_prefix, $txt, $user_info;
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0
$category = 0 ;
// Set how many posts you want to display
$limit = 5;
// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;
loadLanguage('Stats');
$result = db_query("
SELECT m.ID_BOARD, m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards as b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG = t.ID_FIRST_MSG
AND b.ID_BOARD = m.ID_BOARD
AND $user_info[query_see_board] " .
($category > 0 ? "AND ID_CAT = $category" : "")
. " ORDER BY RAND() LIMIT $limit", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result)){
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['posterTime']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>';
$news['poster'] = !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName'];
$news['locked'] = !empty($row['locked']);
echo '
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster'], '</div>
<div class="post" style="padding: 2ex 0;">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}
mysql_free_result($result);
thanks heaps, Jpdeni!
jpdeni, is it possible to include the posters' avatar on each of the randomly posted topics? thanks in advance! :)
I'm sure that it is possible, but I don't know how to do it. I don't do avatars. Sorry.
can anyone please help?
thanks in advance
ajg,
If you do a search in the block code snippets board for Avatar, you will find some snippets that display Avatars. You may be able to look through some of those code snippets and use some of the code one of them uses and adapt it to display the avatars in this block.
ZarPrime
Working on this...
JP, just to let you know, you need $settings to be declared in your globals - otherwise the little post thingy icon doesn't show up I found .
Here's what I came up with. I haven't done anything really to format the output, I left it to the end user to decide how best to display the avatar. I just did the code to grab the avatar.
global $db_prefix, $txt, $user_info, $settings, $memberContext;
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0
$category = 0 ;
// Set how many posts you want to display
$limit = 5;
// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;
loadLanguage('Stats');
$result = db_query("
SELECT m.ID_BOARD, m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards as b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG = t.ID_FIRST_MSG
AND b.ID_BOARD = m.ID_BOARD
AND $user_info[query_see_board] " .
($category > 0 ? "AND ID_CAT = $category" : "")
. " ORDER BY RAND() LIMIT $limit", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result)){
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}
// Get the avatar...
$memberID = $row['ID_MEMBER'];
loadMemberData($memberID);
loadMemberContext($memberID);
$news['avatar'] = $memberContext[$memberID]['avatar']['image'];
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['posterTime']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>';
$news['poster'] = !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName'];
$news['locked'] = !empty($row['locked']);
echo '
<div>' ,
$news['avatar'] , '
</div>
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster'], '</div>
<div class="post" style="padding: 2ex 0;">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}
mysql_free_result($result);
You could put some padding round the avatar maybe, split it all into two halves or whatever.
Hi freddy,
I figured you would pick up on this. Good job. :up:
I knew that $memberContext was required in the globals but I had forgotten about $settings. Keep up the good work. ;)
ZarPrime
No problem Zar. Funnily enough I was working on something the other day to grab the avatars myself for a mod I am working on. Glad I could help.
Just remember that each time you call the loadMemberContext to grab this info, you add a query to the database. I thought it a good idea to loop through that function for an array of members once, and it added like 10 queries because I was trying to get 10 users avatars. For this code it works great, but if you wanted to get more than one user, you'd be better to combine your query into a single one just to grab the avatar info. Just my $.02 :)
Yeah that sounds wise. I was a little worried by the overheads, but figured it would be okay for this. For my mod I could need to pull quite a few avatars so I will give your suggestion a go.
P.S. I was trying to look up the function in the SMF functions database but for some reason it's been down since yesterday it looks like. They're working on it. What I may do is take a look at the details and maybe post an alternative.
I've blocked your PM's.... :P No seriously, some posts must have been removed or something as we have a limit of 5 posts here before you can PM. Anyway, one more post and you can PM me I think. I've been getting a ton of PM's lately, and I'm not getting notifications for any of them for some reason. So I most likely have missed something if you sent one. I'll send you an email shortly. You picked an odd place to post for my attention. lol
ok thx
woww... thank you very much freddy888 for the code!!! might have some more questions for you.. ;)
You are welcome :)
Probably just needs some work on the layout still so it's just the way you want it...
hello freddy888
it took me ages to come up with the formatting. so as not to change so much in jpdeni's code, here is what i thought.
avatar image post icon and post title
date and time of post
display name
please get rid of the word "by" before the username.
please put a thin border around the avatar.
a provision to resize the avatar
a provision to have a generic avatar for those without an avatar
thanks once again!
Hi ajg, yes that looks do-able. So basically you want the avatar over on the left-hand side like a forum post ? And everything else on the right? Not sure where you want the actual message to appear...maybe like this :
Avatar | post icon & title
| date and time
| display name
--------------------------------------------
main message underneath ?
please get rid of the word "by" before the username - no problem
please put a thin border around the avatar - no problem
a provision to resize the avatar - that should be fine
a provision to have a generic avatar for those without an avatar - can do I think..
I need to go to the shops now (darn RealLife!) but it shouldn't be too long a wait.
Cheers.
that's exactly what i want please. thanks in advance!
Ok mate. I went out tonight or I would have posted it already. I am working on it, I'll drop it in tomorrow (getting late here) at some point. Cheers :)
no worries! cheers, mate
OK here goes...
There's some new configurations which are pretty self-explanatory but I will just mention them here.
$avatararea - sets the width of the avatar container - this is a percentage. Depending on how wide your forum is you will probably need to play with this setting for the best and most even layout.
$avwidth, $avheight - override the actual size of the avatar image, should look OK if your avatars are mostly square.
$noavatarurl - currently set to look in the root directory - ie in the same location as your SMF index.php for a file called 'noavatar.jpg'. Just change this to whereever you want to put it or just leave it alone. You will need the 'no avatar' image copied to your root - I've attached a few versions - just change the name of the one you like to 'noavatar.jpg' and drop it in your forum root.
I tested this on a few themes and it seems to be fine.
Let me know how you get on :)
global $db_prefix, $txt, $user_info, $settings, $memberContext;
// Configuration...
// Percentage width of avatar area
$avatararea = 15;
// Colour of border around avatar
$avbordercol= '#fff';
// Default width and height of avatar
$avwidth = 75;
$avheight= 75;
// Path to 'no avatar' image.
$noavatarurl = 'noavatar.jpg';
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0
$category = 0 ;
// Set how many posts you want to display
$limit = 5;
// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;
loadLanguage('Stats');
$result = db_query("
SELECT m.ID_BOARD, m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards as b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG = t.ID_FIRST_MSG
AND b.ID_BOARD = m.ID_BOARD
AND $user_info[query_see_board] " .
($category > 0 ? "AND ID_CAT = $category" : "")
. " ORDER BY RAND() LIMIT $limit", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result)){
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}
// Get the avatar and build the image link for it, if it exists...
$memberID = $row['ID_MEMBER'];
loadMemberData($memberID);
loadMemberContext($memberID);
if (!empty($memberContext[$memberID]['avatar']['href']))
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['posterName'] . '" title="' . $row['posterName'] . '" src="' . $memberContext[$memberID]['avatar']['href'] . '" />';
}
else
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['posterName'] . '" title="' . $row['posterName'] . '" src="' . $noavatarurl . '" />';
}
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['posterTime']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>';
$news['poster'] = !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName'];
$news['locked'] = !empty($row['locked']);
// Display it all...
echo '
<div style="width:100%;display:table">
<div style="width: ' , $avatararea , '%;float:left;text-align:center">
' , $news['avatar'] , '
</div>
<div style="width: ' , 99 - $avatararea , '%;float:right">
<a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], '<br />' , $txt[525] , ' ' , $news['poster'], '</div>
</div>
<div class="post" style="padding: 2ex 0;clear:both">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}
mysql_free_result($result);
thanks freddy888! just another thing, can you please include the word "by" before the username. sorry, i know i asked for it to be deleted by it just doesn't look nice without it.. my bad.. thanks heaps, though.. maybe edit the above code so as not to confuse the others..
No problem - that's been edited now... :D
Maybe you can drop a link so others can see it in action ? I don't have a site I need to use it on at the moment.
Cheers :)
thanks again freddy888.. i'm still playing with my site a bit, so once it's full on, i'll provide a link.. thanks once again freddy888 and jpdeni..
Okay my friend, no pressure...and yes thanks to JPDeni from me too :)
jpdeni and/or freddy888,
this code can display random topics from certain category/ies. how can i display random topics from a specific board/s. i still want the avatars displayed..
thanks in advance guys.. still using TP098 and SMF 11
Change
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0
$category = 0 ;
to
// If you want to limit it to one board, enter the category number here
// If you want to use all boards, set it to 0
$board = 0 ;
And change
AND $user_info[query_see_board] " .
($category > 0 ? "AND ID_CAT = $category" : "")
. " ORDER BY RAND() LIMIT $limit", __FILE__, __LINE__);
to
AND $user_info[query_see_board] " .
($board > 0 ? "AND b.ID_BOARD = $board" : "")
. " ORDER BY RAND() LIMIT $limit", __FILE__, __LINE__);
thanks once again, jpdeni :up: i will try out later... much appreciated
I didn't test it, but it should work. Just some simple substitutions.
Hi Freddy !
I test as admin that code(first code because I'm not interested to show avatars) in a .php article for front page, after I see is possible with a replacement to show from a specific board instead of category.
I have 2 questions :
1. Is possible after the topic appear to be the title of topic click able and linked ?... when user click the title of topic what appear in article to go to that topic ?(now is possible only if click at comments....down article page-> ugly)
2. Is possible to show random from specific boards not only 1 board( Ex: board 12, 15 etc; ? )
I must first test as admin...before to make it for all users.
10x in advance !
So you want to remove the 'x Comments | Write Comment' bit and instead put the link into the topic title.... yes I can do that.
When you say 'boards' you really do mean boards and not categories ?
I am assuming you are on SMF 1 ?
Can this code suitable with smf v2?
Not yet, I will try and convert it. Back later ...
I've put the new version for SMF 2 in the new block area here :
http://www.tinyportal.net/index.php?topic=33286
It's producing no errors for me. Test it out and let us know how you get on :)
yes.. nice.. but how to make clickable subject link?
I find it.. tq..
Now im using a simple code
// Display it all...
echo '
<div style="width:100%;display:table">
<img src="http://myweb/bullet.png" alt="" style="margin: 0pt 2px 0pt 0pt;" border="0"><a href="', $news['href'], '">', $news['subject'], '</strong>
';
}
mysql_free_result($result);
i want to show 8 topics with to colums... how can i get it?
I'm away for a few days now, See if you can figure it out. Have fun.
hope there is a way to limit subject character. tq
Quote from: QUBBAH on October 20, 2010, 06:49:47 AM
hope there is a way to limit subject character. tq
Hope anybody can help.
QUBBAH,
Freddy is away on a brief holiday. I'm sure he will return shortly and will be able to help you out. Please be patient. ;)
ZarPrime
Thanks ZP :)
I am back now, but have a lot of other stuff I need to catch up on first. I'll get to you at some point, just not sure exactly when at the moment.
is this code is still suitable with smf 2.0.6?
As far as I can tell, the code that Freddy posted should work with SMF2 and TP 1. No way to know for sure unless you try it. :)
i tried it with smf 2.0.6 and it cant be done... its okay with smf 2.0 rc3
MrCare,
What does the block look like? Any errors in your error log?
ZarPrime
If he's using the SMF2 code I put here then I think all it needs is converting up to use the smcFunc...
http://www.tinyportal.net/index.php?topic=33286
Try to add smfunc but cant be done..
global $db_prefix, $txt, $user_info, $settings, $smcFunc, $memberContext, $scripturl, $boardurl;
Yes fine the problem..
Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 2.0.6, while your database is at version 2.0 RC3. The above error might possibly go away if you execute the latest version of upgrade.php.
How can i solve this.. coz my forum can't be upgrade.. always stuck while upgrade.. tq
That is not an error that TP has anything to do with. You should check with the SMF folks for your problem.
Still having a problem to make random topic for new smf version 2.0.7 and latest tp version.
Quote from: MrCare on June 06, 2014, 04:41:28 PM
Still having a problem to make random topic for new smf version 2.0.7 and latest tp version.
still waiting...
Haven't you learnt to code yet ? ;)
I will try and convert it over the next few days if I get time.
I had time to do it tonight between the football almost. Try this :
http://www.tinyportal.net/index.php?topic=33286.msg282305#msg282305 (http://www.tinyportal.net/index.php?topic=33286.msg282305#msg282305)
I leave you to do the styling and CSS.
hi, how can i exclude categories from the random topics? Thanks a lot.
are you using the code linked in the post above yours? if so you can define categories to use, but not categories you want to ignore. so you can list all the categories you want to use.
yes i am using this:
global $txt, $user_info, $settings, $memberContext, $scripturl, $boardurl, $smcFunc;
// Configuration...
// Percentage width of avatar area
$avatararea = 30;
// Colour of border around avatar
$avbordercol= '#fff';
// Default width and height of avatar
$avwidth = 35;
$avheight= 35;
// Path to 'no avatar' image.
$noavatarurl = $boardurl . '/Themes/default/images/noavatar.jpg';
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0
$category = 0 ;
// Set how many posts you want to display
$limit = 5;
// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;
loadLanguage('Stats');
$result = $smcFunc['db_query']('', "
SELECT m.id_board, m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked
FROM ({db_prefix}topics AS t, {db_prefix}messages AS m, {db_prefix}boards as b)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_msg = t.id_first_msg
AND b.id_board = m.id_board
AND $user_info[query_see_board] " .
($category > 0 ? "AND id_cat = {int:cat}" : "")
. " ORDER BY RAND() LIMIT {int:limit}",
array(
'cat' => $category,
'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}
// Get the avatar and build the image link for it, if it exists...
$memberID = $row['id_member'];
loadMemberData($memberID);
loadMemberContext($memberID);
if (!empty($memberContext[$memberID]['avatar']['href']))
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $memberContext[$memberID]['avatar']['href'] . '" />';
}
else
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $noavatarurl . '" />';
}
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['poster_time']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['id_topic'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>';
$news['poster'] = !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'];
$news['locked'] = !empty($row['locked']);
// Display it all...try your own styling. Might be better in a table.
echo '
<div style="width:100%;display:table">
<div style="width: ' , $avatararea , '%;float:left;text-align:center">
' , $news['avatar'] , '
</div>
<div style="width: ' , 99 - $avatararea , '%;float:right">
<a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], '<br />' , $txt['by'] , ' ' , $news['poster'], '</div>
</div>
<div class="post" style="padding: 2ex 0;clear:both">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}
$smcFunc['db_free_result']($result);
but if i change $category = 0 ; for another number or numbers separate by comma, it doesn't show anything. Can you help me?
try something like this
$category = array(1,3,10);
at the beginning i used it... and it show:
Wrong value type sent to the database. Integer expected. (cat)
then i guess the script will only work with 1 category or all categories.
Quote from: illori on October 14, 2015, 04:24:37 PM
then i guess the script will only work with 1 category or all categories.
Yes that is correct. I just adapted it so you can exclude categories. Try this...
Just set this to zero...
$category = 0;
Then set $exclude to an array of cat ids. For example...
$exclude = array(12, 5, 3);
and it will ignore those.
global $txt, $user_info, $settings, $memberContext, $scripturl, $boardurl, $smcFunc;
// Configuration...
// Percentage width of avatar area
$avatararea = 30;
// Colour of border around avatar
$avbordercol= '#fff';
// Default width and height of avatar
$avwidth = 35;
$avheight= 35;
// Path to 'no avatar' image.
$noavatarurl = $boardurl . '/Themes/default/images/noavatar.jpg';
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0. If you want to exclude cats below set this to zero too.
$category = 0 ;
// Exclude categories ? Use the category ids eg. $exclude = array(3,6);
// Also set $category above to 0 (zero) for this to work.
$exclude = array();
// Set how many posts you want to display
$limit = 5;
// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;
loadLanguage('Stats');
$result = $smcFunc['db_query']('', "
SELECT m.id_board, m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked
FROM ({db_prefix}topics AS t, {db_prefix}messages AS m, {db_prefix}boards as b)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_msg = t.id_first_msg
AND b.id_board = m.id_board
AND $user_info[query_see_board]" .
($category > 0 ? " AND id_cat = {int:cat}" : "")
.
(!empty($exclude) ? " AND id_cat NOT IN ({array_int:exclude})" : "")
. "
ORDER BY RAND() LIMIT {int:limit}",
array(
'exclude' => $exclude,
'cat' => $category,
'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}
// Get the avatar and build the image link for it, if it exists...
$memberID = $row['id_member'];
loadMemberData($memberID);
loadMemberContext($memberID);
if (!empty($memberContext[$memberID]['avatar']['href']))
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $memberContext[$memberID]['avatar']['href'] . '" />';
}
else
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $noavatarurl . '" />';
}
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['poster_time']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['id_topic'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>';
$news['poster'] = !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'];
$news['locked'] = !empty($row['locked']);
// Display it all...try your own styling. Might be better in a table.
echo '
<div style="width:100%;display:table">
<div style="width: ' , $avatararea , '%;float:left;text-align:center">
' , $news['avatar'] , '
</div>
<div style="width: ' , 99 - $avatararea , '%;float:right">
<a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], '<br />' , $txt['by'] , ' ' , $news['poster'], '</div>
</div>
<div class="post" style="padding: 2ex 0;clear:both">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}
$smcFunc['db_free_result']($result);
Thanks a lot but i have just insert it and it doesnt't work for me :-[. I wrote this:
global $txt, $user_info, $settings, $memberContext, $scripturl, $boardurl, $smcFunc;
// Configuration...
// Percentage width of avatar area
$avatararea = 8;
// Colour of border around avatar
$avbordercol= '#fff';
// Default width and height of avatar
$avwidth = 35;
$avheight= 35;
// Path to 'no avatar' image.
$noavatarurl = $boardurl . '/Themes/default/images/noavatar.jpg';
// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0. If you want to exclude cats below set this to zero too.
$category = 0 ;
// Exclude categories ? Use the category ids eg. $exclude = array(3,6);
// Also set $category above to 0 (zero) for this to work.
$exclude = array(54,40,13,43,47,14,38,86,19,83,61,30,34,16,32,17,28,53,41,8,44,48,9,39,45,85,18,82,60,29,35,11,31,10,26,64,59,65,66,77,78,67,68,84,69,81,70,71,72,73,74,75,76);
// Set how many posts you want to display
$limit = 1;
// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;
loadLanguage('Stats');
$result = $smcFunc['db_query']('', "
SELECT m.id_board, m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked
FROM ({db_prefix}topics AS t, {db_prefix}messages AS m, {db_prefix}boards as b)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_msg = t.id_first_msg
AND b.id_board = m.id_board
AND $user_info[query_see_board]" .
($category > 0 ? " AND id_cat = {int:cat}" : "")
.
(!empty($exclude) ? " AND id_cat NOT IN ({array_int:exclude})" : "")
. "
ORDER BY RAND() LIMIT {int:limit}",
array(
'exclude' => $exclude,
'cat' => $category,
'limit' => $limit)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}
// Get the avatar and build the image link for it, if it exists...
$memberID = $row['id_member'];
loadMemberData($memberID);
loadMemberContext($memberID);
if (!empty($memberContext[$memberID]['avatar']['href']))
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $memberContext[$memberID]['avatar']['href'] . '" />';
}
else
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $noavatarurl . '" />';
}
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['poster_time']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['id_topic'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>';
$news['poster'] = !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'];
$news['locked'] = !empty($row['locked']);
// Display it all...try your own styling. Might be better in a table.
echo '
<div style="width:100%;display:table">
<div style="width: ' , $avatararea , '%;float:left;text-align:center">
' , $news['avatar'] , '
</div>
<div style="width: ' , 99 - $avatararea , '%;float:right">
<a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], '<br />' , $txt['by'] , ' ' , $news['poster'], '</div>
</div>
<div class="post" style="padding: 2ex 0;clear:both">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}
$smcFunc['db_free_result']($result);
I only let 2 board to show (to see it is correct), but it doesn't work. Are there any bad????
The problem with this script is that can show private content from boards, i guess.
Thanks so much.
$exclude needs to be the cats you want left out.
Yes, i understood but it didn't work for me. It show all the boards and the exlude boards too.
are you entering the numbers for the CATEGORIES or the numbers for the BOARDS. you need to make sure they are the id numbers for the CATEGORIES, if you have a category with both public and private boards in it, then you need to exclude that CATEGORY.
Quote from: illori on October 16, 2015, 12:47:25 PM
are you entering the numbers for the CATEGORIES or the numbers for the BOARDS. you need to make sure they are the id numbers for the CATEGORIES, if you have a category with both public and private boards in it, then you need to exclude that CATEGORY.
You have rights, I was put id boards instead id cats. Thanks a lot men!!
How can I get this to display in exactly the same manner / format as the 'Recent Topics' block?
(So just avatar, title, author, date/time)
I don't want any preview etc.
Thanks