Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

December 06, 2022, 07:18:22 AM

Login with username, password and session length
Members
  • Total Members: 3853
  • Latest: tty456
Stats
  • Total Posts: 193627
  • Total Topics: 21108
  • Online today: 101
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 0
Guests: 71
Total: 71

Author Topic: [Discussion] Random topic  (Read 42849 times)

0 Members and 1 Guest are viewing this topic.

Offline MrCare

  • Jr. Member
  • **
  • Posts: 62
Re: [Discussion] Random topic
« Reply #50 on: June 06, 2014, 09:41:28 AM »
Still having a problem to make random topic for new smf version 2.0.7 and latest tp version.

Offline MrCare

  • Jr. Member
  • **
  • Posts: 62
Re: [Discussion] Random topic
« Reply #51 on: June 16, 2014, 12:47:14 AM »
Still having a problem to make random topic for new smf version 2.0.7 and latest tp version.
still waiting...

Offline Freddy

  • Moderator
  • *
  • Posts: 1617
    • AiDreams
Re: [Discussion] Random topic
« Reply #52 on: June 17, 2014, 03:25:51 PM »
Haven't you learnt to code yet ? ;)

I will try and convert it over the next few days if I get time.

Offline Freddy

  • Moderator
  • *
  • Posts: 1617
    • AiDreams
Re: [Discussion] Random topic
« Reply #53 on: June 17, 2014, 04:12:05 PM »
I had time to do it tonight between the football almost.  Try this :

http://www.tinyportal.net/index.php?topic=33286.msg282305#msg282305

I leave you to do the styling and CSS.

Offline ayozeve

  • Jr. Member
  • **
  • Posts: 6
Re: [Discussion] Random topic
« Reply #54 on: October 14, 2015, 08:03:16 AM »
hi, how can i exclude categories from the random topics? Thanks a lot.

Offline illori

  • Administrator
  • *
  • Posts: 2075
Re: [Discussion] Random topic
« Reply #55 on: October 14, 2015, 08:11:49 AM »
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.

Offline ayozeve

  • Jr. Member
  • **
  • Posts: 6
Re: [Discussion] Random topic
« Reply #56 on: October 14, 2015, 08:52:48 AM »
yes i am using this:

Code: [Select]
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?

Offline illori

  • Administrator
  • *
  • Posts: 2075
Re: [Discussion] Random topic
« Reply #57 on: October 14, 2015, 08:57:14 AM »
try something like this

Code: [Select]
$category = array(1,3,10);

Offline ayozeve

  • Jr. Member
  • **
  • Posts: 6
Re: [Discussion] Random topic
« Reply #58 on: October 14, 2015, 09:02:31 AM »
at the beginning i used it... and it show:

Wrong value type sent to the database. Integer expected. (cat)

Offline illori

  • Administrator
  • *
  • Posts: 2075
Re: [Discussion] Random topic
« Reply #59 on: October 14, 2015, 09:24:37 AM »
then i guess the script will only work with 1 category or all categories.