home forums resources search newsjoinmembers: 6381
Hiveminds Network PHP Flash Java Ruby Windows Linux
 videos
 articles
 blogs
 comments
 downloads
sitemap
Hiveminds | Mon, 2006-10-16 08:15  tags:

The code added to your template.php file when using the phptemplate engine will get the forum looking more like a real forum.

The Drupal default forum is not very user friendly the layout used here is designed after punBB forum to be clean, fast and with high usability.

The script can be used in Drupal version 4.6 and 4.7 PHPtemplate. The moderation links shown in the picture are not part of this template.

<?php

/**
 * Format the forum listing.
 *
 * @ingroup themeable
 */
function phptemplate_forum_list($forums$parents$tid) {
  global 
$user;
  if (
$forums) {
    
//$header = array(t('Forum'), t('Topics'), t('Posts'), t('Last post'));
    //$header = array();
    
foreach ($forums as $key=>$forum) {
      if (
$forum->container) {
        
$description  '<div style="margin-left: '. ($forum->depth 30) ."px;\">\n";
        
$description .= ' <div class="name">'l($forum->name"forum/$forum->tid/container") ."</div>\n";
        if (
$forum->description) {
          
$description .= " <div class=\"description\">$forum->description</div>\n";
        }
        
$description .= "</div>\n";
        
$rows[] = array(array('data' => $description'class' => 'container''colspan' => 4));
        
$rows[] = array(
        array(
'data' => t('Subject'), 'class' => 'f-subject'),
        array(
'data' => t('Topics'), 'class' => 'f-topics'),
        array(
'data' => t('Posts'),'class' => 'f-posts'),
        array(
'data' => t('Last post'),'class' => 'f-last-reply')
        );
      }
      else {
        
$forum->old_topics _forum_topics_unread($forum->tid$user->uid);
        if (
$user->uid) {
          
$new_topics $forum->num_topics $forum->old_topics;
        }
        else {
          
$new_topics 0;
        }
        
$description  '<div style="margin-left: '. ($forum->depth 30) ."px;\">\n";
        
$description .= ' <div class="name">'l($forum->name"forum/$forum->tid") ."</div>\n";
        if (
$forum->description) {
          
$description .= " <div class=\"description\">$forum->description</div>\n";
        }
        
$description .= "</div>\n";
        
$rows[] = array(
          array(
'data' => $description'class' => 'forum'),
          array(
'data' => $forum->num_topics . ($new_topics '<br />'l(t('%a new', array('%a' => $new_topics)), "forum/$forum->tid"NULLNULL'new') : ''), 'class' => 'topics'),
          array(
'data' => $forum->num_posts'class' => 'posts'),
          array(
'data' => _forum_format($forum->last_post), 'class' => 'last-reply'));
      }
    }
    
/**
     * set table header if page is a container with listing of forums
     */
    
if(in_array(arg(1), variable_get('forum_containers', array()))){
            
// reverse array
            
$nrows array_reverse($rows,true);
            
//get the container description
            
$container taxonomy_get_term(arg(1));
            
//add to output
            
$rows $nrows;
            
$rows[] = array(
                array(
'data' => t('Subject'), 'class' => 'f-subject'),
                array(
'data' => t('Topics'), 'class' => 'f-topics'),
                array(
'data' => t('Posts'),'class' => 'f-posts'),
                array(
'data' => t('Last post'),'class' => 'f-last-reply')
                );
            
$rows[] = array(array('data' => $container->description'class' => 'container''colspan' => 4));
            
//reverse again to output
            
$nrows array_reverse($rows,true);
            
$rows $nrows;
        }
    return 
theme('table'$header$rows);
  }
}
?>

printer-friendly version

Hiveminds's picture
This article brought to you by the Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously
 
 

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.

page top