Hey!
Of course, here you got it!
This is the extended version... About half of the code is not needed, but I still had no time to remove the not needed parts. So you have to figure out, in case of my settings on top, which parts are the important.
I structured it a bit and made it more readable so it should be clear!
The main extension is that we now have a filter on "board_id". So only posts of this board will be listed!
// **************************************************
// *** SETTINGS
// **************************************************
$board_id = 5; // NEWS
// POST SETTINGS BELOW
$show_posts = '1'; //Set to 1 if you want to show posts
$posts_root_only = '1'; // Only root posts (fist post of a thread (parent = 0))
$posts_last_added = '1'; //Set to 1 if you want to show last added posts
$posts_dynamic = '0'; //Set to 1 if you want to show dynamicly posts from current board
// THREADS SETTINGS BELOW
$show_threads = '0'; //Set to 1 if you want to show threads
// ONLY STICKY THREADS
$threads_sticky = '1'; // Set this to 1 if you want only sticky threads
// SELECT ONLY 1 OF 3 OPTIONS BELOW
$threads_last_posted = '1'; //Set to 1 if you want to show lastly active threads
$threads_most_viewed = '0'; //Set to 1 if you want to show most viewed threads
$threads_most_reply = '0'; //Set to 1 if you want to show threads with most reply's
$order = 'DESC'; //Set ASC for A->Z or DESC for Z->A
$limit = '5'; //Set limit count for results outputed which to be showed
$letters_limit = '120'; //Set letters limit for description of posts messages
$user_real_name = '1'; //Set to 1 if you want to show First Last names, set to 0 for username
// **************************************************
// *** QUERY
// **************************************************
if($show_threads == '1'){
$c = $modx->newQuery('disThread');
}else{
$c = $modx->newQuery('disPost');
}
// **************************************************
// *** SORTATION
// **************************************************
if(($show_posts == '1') AND ($posts_last_added == '1')){
$c->sortby('createdon',$order);
}else{}
if(($show_threads == '1') AND ($threads_last_posted == '1')){
$c->sortby('post_last_on',$order);
}else{}
if(($show_threads == '1') AND ($threads_most_viewed == '1')){
$c->sortby('views',$order);
}else{}
if(($show_threads == '1') AND ($threads_most_reply == '1')){
$c->sortby('replies',$order);
}else{}
// **************************************************
// *** FILTER
// **************************************************
if($show_threads == '1'){
if($board_id != 0){
$c->where(array( 'board' => $board_id, 'private' => '0' ));
}else{
$c->where(array( 'private' => '0' ));
}
}else{
// If specific board id was defined in parameters
if($board_id != 0){
// Get all threads of a board and all posts of these threads
// Because: Posts will not be deleted when a thread is deleted! -.-
$t = $modx->newQuery('disThread');
$t->where(array('board' => $board_id));
if($threads_sticky == '1'){
$t->where(array('sticky' => '1'));
}
$thread_list = array();
$threads = $modx->getCollection('disThread',$t);
foreach ($threads as $thread) {
array_push($thread_list, array('thread' => $thread->get('id')));
}
$c->where($thread_list, xPDOQuery::SQL_OR);
}else{
//If we are in main board page
if((strip_tags($_GET['board']) != '') AND ($posts_dynamic == '1')){
$c->where(array('board' => strip_tags($_GET['board'])));
}else{}
//If we are in thread page
if((strip_tags($_GET['thread']) != '') AND ($posts_dynamic == '1')){
$t = $modx->newQuery('disThread');
$t->where(array('id' => strip_tags($_GET['thread'])));
$t->limit(1,0);
$boards = $modx->getCollection('disThread',$t);
foreach ($boards as $board) {
$c->where(array('board' => $board->get('board')));
}
}else{}
}
if($posts_root_only == '1'){
$c->where(array( 'parent' => '0' ));
}
}
// **************************************************
// *** LIMIT
// **************************************************
$c->limit($limit,0);
// **************************************************
// *** GET THE RESULT
// **************************************************
if($show_threads == '1'){
$resources = $modx->getCollection('disThread',$c);
}else{
$resources = $modx->getCollection('disPost',$c);
}
// **************************************************
// *** BUILD OUTPUT
// **************************************************
$is_first = true;
$output = '';
foreach ($resources as $res) {
if($show_threads == '1'){
$output .= '<li class="rthread"><a href="forum/thread/'.$res->get('id').'/'.strtolower($res->get('title')).'">'.$res->get('title').'</a>';
$a = $modx->getObject('disUser', array('id' => $res->get('author_first')));
$output .= ' by <a class="rauthor" href="forum/u/'.$a->get('username').'/">';
if($user_real_name == '1'){
$output .= $a->get('name_first').' '.$a->get('name_last').'</a>';
}else{
$output .= $a->get('username').'</a>';
}
$output .= '</li>';
}else{
// **************************************************
// *** COLLECT ALL INFORMATIONS (just for clear view)
// **************************************************
$thread = $modx->getObject('disThread', array('id' => $res->get('thread')));
$author = $modx->getObject('disUser', array('id' => $res->get('author')));
$thread_title = $res->get('title');
$thread_content = $res->getContent();
$thread_author = $author->get('username');
$thread_created_date = date("j. F Y");
$thread_created_time = date("H:i");
$thread_replies = $thread->get('replies');
$thread_reply_last = $thread->get('post_last');
// **************************************************
// *** BUILD HTML
// **************************************************
if($is_first == true){
$is_first = false;
$output .= '<div class="pe-news-entry first block">';
}else{
$output .= '<div class="pe-news-entry block">';
}
$output .= '<div class="pe-news-entry-header block">';
$output .= '<div class="pe-news-entry-field title block">';
$output .= "<i class=\"fa fa-chevron-down\"></i><a href=\"/forum/thread/" . $res->get('thread') . "\">" . $thread_title . "</a>";
$output .= '</div>';
$output .= '</div>';
$output .= '<div class="pe-news-entry-main block">';
$output .= '<div class="pe-news-entry-field content block">';
$output .= $thread_content;
$output .= '</div>';
$output .= '</div>';
$output .= '<div class="pe-news-entry-footer block">';
$output .= '<div class="pe-news-entry-field author block">';
$output .= "<a href=\"/members.html?u=$thread_author\">" . $thread_author . "</a>";
$output .= '</div>';
$output .= '<div class="pe-news-entry-field date block">';
$output .= "am " . $thread_created_date . " um " .$thread_created_time . "Uhr";
$output .= '</div>';
$output .= '<div class="pe-news-entry-field comments block">';
$output .= "<a href=\"/forum/thread/" . $res->get('thread') . "\">";
if($thread_replies == '1'){
$output .= $thread_replies . " Kommentar";
}else{
$output .= $thread_replies . " Kommentare";
}
$output .= "</a>";
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
/*
$output .= $thread_created_date . $thread_created_time;
$output .= '<li class="rpost"><a href="forum/thread/'.$res->get('thread').'/'.strtolower($res->get('title')).'#dis-post-'.$res->get('id').'">'.$res->get('title').'</a>';
$output .= '<p>'.mb_substr($res->get('message'), 0, $letters_limit).'</p>';
$a = $modx->getObject('disUser', array('id' => $res->get('author')));
$output .= ' by <a class="rauthor" href="forum/u/'.$a->get('username').'/">';
if($user_real_name == '1'){
$output .= $a->get('name_first').' '.$a->get('name_last').'</a>';
}else{
$output .= $a->get('username').'</a>';
}
$output .= '</li>';
$output .= $res->getContent();
*/
}
}
return $output;
So I hope this helps you out! =)