Store
Community Documentation

v3 Knowledgebase

[Forum Tutorial] Block to show the last 5 thread entries

NOTE: if you want the advance version of this mod go here: http://www.phpfox.com/addons/view/list-the-last-forum-entries/

This was a long day of understanding some tricks from this new version to accomplish this. Probably there are simpler ways of doing this, but this is the one I have come to.

There is a little thing missing, and that is if your members don't upload an avatar image nothing is shown. If some one knows how to do that, please feel free to add that to the code.(this was fixed in the advanced version)

This is not hard coding, and I haven't edit any file. This was all made with a simpler php block in admincp.

So to start you must create a PHP block and add it to the dashboard (core.index-members)

[ADDED BY PHPFOX]

1. Go to CMS > Add New Block
2. - Module: Forum
- Title: List latest forum threads.
- Type: PHP Code
- Controller: (You choose where)
- Placement: (You choose where)
- PHP/HTML Code: Copy and paste the code below

[ADDITION END BY PHPFOX]

The code you must past is this:
PHP:
<?php

$aRows 
Phpfox::getLib('phpfox.database')
          ->
select('a.title, a.total_post, a.total_view, a.title_url, b.name, b.name_url, b.forum_id, c.user_image, c.user_name')
            ->
from(Phpfox::getT('forum_thread'), 'a')
            ->
join(Phpfox::getT('forum'), 'b''a.forum_id = b.forum_id')
            ->
join(Phpfox::getT('user'), 'c''a.user_id = c.user_id')
            ->
limit(5)
        ->
where('group_id = 0')
            ->
order('time_update DESC')
            ->
execute('getRows');  


echo 
'<div class="block js_sortable"><div class="title js_sortable_header">Last Forum Threads</div><div class="content"><div id="bulletin_header_2"></div>';

foreach (
$aRows as $aRow)
{

     
$avatarpath Phpfox::getParam('core.url_user');
     
$avatarpath .= $aRow['user_image'];
     
$avatarpath str_replace("%s","_50",$avatarpath);

     echo 
'<div class="row_title"><div class="row_title_image"><a href="'.Phpfox::getParam('core.path').'index.php?do=/'.$aRow['user_name'].'"><img src="'.$avatarpath.'" width=50 height=50></a></div>';
     echo 
'<div class="row_title_info"><a href="'.Phpfox::getParam('core.path').'index.php?do=/forum/'.$aRow['name_url'].'/'.$aRow['title_url'].'">'.$aRow['title'].'</a>';
     echo 
'<div class="extra_info">';
     echo 
'Forum: <a href="'.Phpfox::getParam('core.path').'index.php?do=/forum/'.$aRow['name_url'].'-'.$aRow['forum_id'].'">'.$aRow['name'].'</a>This thread as '.$aRow['total_post'].' posts and was viewed '.$aRow['total_view'].' times.</div></div></div><div id="bulletin_2" class="row1"></div>';

}
echo 
'</div></div>';       
?>


I don't have activity in my forum, so if some of you use it please PM me your sites url so I can see it running on a live site.



Thanks