Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: MarkoKg - joulukuu 16, 2013, 02:51:59 IP

Otsikko: Display only the one latest news item?
Kirjoitti: MarkoKg - joulukuu 16, 2013, 02:51:59 IP
Hello there.

Is it possible to show (somewhere in template) just one latest news item?
So, if I have for example 8 news items, i want just last one 8th to be shown.

Thanks  ;)
Otsikko: Re: Display only the one latest news item?
Kirjoitti: Matthew K. - joulukuu 16, 2013, 03:10:35 IP
Sure...

echo $context['news_lines'][count($context['news_lines']) - 1];
Otsikko: Re: Display only the one latest news item?
Kirjoitti: Matthew K. - joulukuu 16, 2013, 03:11:56 IP
For future reference, or in case you are interested, you'll want to look into ./Sources/Subs.php. The news at the top of the forum "News", which pulls out a random news item, is found in Subs.php, also with $context['news_lines'], which is from a $modSettings variable.
// Get some news...
$context['news_lines'] = explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))));
$context['fader_news_lines'] = array();
for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
{
if (trim($context['news_lines'][$i]) == '')
continue;

// Clean it up for presentation ;).
$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);

// Gotta be special for the javascript.
$context['fader_news_lines'][$i] = strtr(addslashes($context['news_lines'][$i]), array('/' => '\/', '<a href=' => '<a hre" + "f='));
}
$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];