Customizing SMF > Tips and Tricks
Showing "category" images with boardnews ssi
Jim Yarbro:
My own little dooah here... got rid of all the extra bracks, and made it variable so that it's more easily expandable, and the code ports easier. also there were a couple bugs.. cant remember the second one but hte first one was that if the variable thing came at the front of the subject, it wouldnt work cuz the strpos was 0, which wouldnt register properly. !== false took care of that.
--- Code: ---<?php
use [Unknown]'s;
?>
--- End code ---
[Unknown]:
Oops, I knew I forgot something, meant to add the !== false on.
--- Code: ---<?php
$array = ssi_boardNews(null, 5, null, 350, 'array');
$newsCategories = array('php','mysql','perl');
foreach ($array as $news)
{
$found = false;
// Check which tag is present in the subject, delete it and use the image.
foreach ($newsCategories as $cat)
{
if (strpos(strtolower($news['subject']), '[' . $cat . ']') !== false)
{
echo '
<h5><a href="', $news['href'], '">', preg_replace('~\[' . $cat . '\]~i', '', $news['subject']), '</a></h5>
<img src="img/', $cat, '.png" align="left" alt="', $cat, '" />', $news['body'], '<br />';
$found = true;
}
}
// If no tag is present, just show the news.
if (!$found)
echo '
<h5><a href="', $news['href'], '">', $news['subject'], '</a></h5>
', $news['body'], '<br />';
}
?>
--- End code ---
I have this big time pet peeve with using 1/0 when you want true/false.
-[Unknown]
Jim Yarbro:
yeah its something im trying to get in the habit of not doing. its just a bad ol habit from perl days :)
Tim:
isn't open source swell :)
Navigation
[0] Message Index
[*] Previous page
Go to full version