Show posts from your SMF fourm in your home/index page


SMF forum is quit popular open source forum application used by many websites as their main bulletin board. Some time we need to grab posts,topics from the board and show them on our home/index page or anywhere on our site. To make the things much easier, SMF provides all this in one script where we call a function with arguments and dress it up according to our needs. File is SSI.php and can be found in the root folder of the forum. You can also add extra parameters/piece of code to your SSI.php. In this post i will show you how to retrieve posts from SMF board with additional information like board, post author, date & time plus top poster and board statistics.

1
$PostList = ssi_recentPosts(8, null, null, 'array');

The above piece of code will pull the last 8 posts from the forum db, as you can see i used array this is because i want to dress up my code like open links in new tab/window etc.

1
2
3
4
5
6
7
8
9
10
11
12
foreach ($PostList as $Post) {
//echo '<pre>', print_r($Post), '</pre>';
echo "<tr>";
echo "<div class='forum_posts'>";
echo '<td width="350px"><a target="_blank" href=', $Post['href'], '>', $Post['subject'], '</a></td>',
'<td width="250px"><a target="_blank" href=', $Post['board']['href'], '>',$Post['board']['name'],'</a></td>',
'<td width="100px"><a target="_blank" href=', $Post['poster']['href'], '>', $Post['poster']['name'], '</a></td>',
'<td width="150px">',$Post['time'],'</td>';
echo "</div>";
echo "</tr>";
}
unset($PostList);

The above code will loop the 8 results and print it on the page with post subject, board, poster name and date.

Now the additional stuff like top poster and board statistics:

1
2
<strong>Top Poster : </strong><?php ssi_topPoster();?> <hr id='line-hr'>
<strong>Forum Stats : </strong><?php ssi_boardStats(); ?> <hr id='line-hr'>

Above are the main code which will pull the things for you, now lets put the whole code in one place with html and its css.

Full code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<h2>My Forum Recent Happenings!</h2>
<strong>Recent Posts : </strong>
<table class='main'>
<tr>
<th>Post</th><th>Board</th><th>Posted by</th><th>Time</th>
</tr>

<?php
$PostList = ssi_recentPosts(8, null, null, 'array');
foreach ($PostList as $Post) {

echo "<tr>";
echo "<div class='forum_posts'>";

echo '<td width="350px"><a target="_blank" href=', $Post['href'], '>', $Post['subject'], '</a></td>',
'<td width="250px"><a target="_blank" href=', $Post['board']['href'], '>',$Post['board']['name'],'</a></td>',
'<td width="100px"><a target="_blank" href=', $Post['poster']['href'], '>', $Post['poster']['name'], '</a></td>',
'<td width="150px">',$Post['time'],'</td>';

echo "</div>";
echo "</tr>";
}
unset($PostList);
?>
</table>
<strong>Top Poster : </strong><?php ssi_topPoster();?> <hr id='line-hr'>
<strong>Forum Stats : </strong><?php ssi_boardStats(); ?> <hr id='line-hr'>

You can put this code any where you want in you pages, just to make sure include the css below in the head tag of the header file(home/index etc etc) like:

1
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

CSS file code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Table Layout */
table.main {
margin-top: .5em;
margin-bottom: .5em;
margin-left: .0em;
margin-right: .0em;
background: whitesmoke;
border-collapse: collapse;
font-size: 13px;
font-family: Arial;
}
table.main tr:hover {
background: #E6E6E6 !important;
}
table.main td {
border: 0px silver solid;
padding: 0.5em;
text-align:left;
border-bottom:1px silver solid;
}
table.main th {
border: 0px silver solid;
border-bottom:2px silver solid;
padding: 0.5em;
background: gainsboro;
text-align: left;
}
table.main caption {
margin-left: inherit;
margin-right: inherit;
}
/* Table Laout Ends */

/* Hr */
#line-hr {
height:1px;
margin-top:7px;
margin-bottom:7px;
background-color: silver;
border: 0px solid;
}
/* Hr Ends */

/* Forum Posts */
.forum_posts {
margin-top: 5px;
margin-bottom: 5px;
border-bottom: 0px solid #000;
}
.forum_posts a:link {
text-decoration: underline;
}
.forum_posts a:hover {
text-decoration: none;
color: #ea4900;
}
.forum_posts #time {
float: right;
}
/* Forum Posts Ends */

Save this file as style.css and include it in your head tag of the home/index page.

And that’s it, we are done… any question in mind use the comment section or you can ask in the SMF forum.

  • Edgardo

    Hi, very good article.

    One question, do you know how could I insert the latest posts into, lets say, a wordpress home page?

    Thanks!

  • Hi Edgardo,

    I’m afraid i did not get you clearly, but what i assume are:
    1- Do you mean to show smf forum posts on your wordpress blog?
    2- Do you mean to show posts from wordpress blog on your home page?
    Or i get it wrong?
    Hope i could be of any help.

    Regards

  • Jamie

    Thank you very much for this examples. I was struggling to get it to work! And css implementation looks wonderful!

Search

Articles

What's Hot

Recent Comments