Hi ! I know you can do this with forum nodes using flat forum, but has anybody themed the actual forum page, that which contains all the forum lists, threads and so forth?

Any examples of this having been done? Many thanks

Comments

heine’s picture

The forum list is generated by several theme functions.

theme_forum_display for the page
theme_forum_list for the actual forum list and
theme_forum_topic_list for the topic lists

Refer to the phptemplate docs to see how to override additional theme functions using template.php.

Use the code from the theme_forum_* functions as an example how to get your own output. You can find them in forum.module line 755, 834 and 889.

--
When your problem is solved, please post a follow-up to the thread you started.

luyendao’s picture

Thank you Heine, just by listing those functions, i somewhat understand how over-riding themes works now. Not being a programmer, it's taking me a bit longer to "get it"...but i will give it a go.

heine’s picture

I found some more time this night (note this is all quick and perhaps not the ideal way to do something):

You can do a lot with CSS alone. Sometimes you need to rearrange certain parts of the forum.
First of all, get yourself a phptemplate theme if you don't have it already.

Create or append to the_theme/template.php:

/**
  * Captures the forum list and passes control to forum-list.tpl.php.
  * The variables, $forums, $parents and $tid will be available in forum-list.tpl.php
  */
function phptemplate_forum_list($forums, $parents, $tid) {
   return _phptemplate_callback('forum-list', array('forums' => $forums, 'parents' => $parents, 'tid' => $tid));   
}

Now you can create the_theme/forum-list.tpl.php to keep it easy simply copy the code from theme_forum_list. You can play around with the builtin styles, perhaps do away with the tables, whatever you want, without hacking core!

  global $user;

  if ($forums) {

    $header = array(t('Forum'), t('Topics'), t('Posts'), t('Last post'));

    foreach ($forums as $forum) {
      if ($forum->container) {
        $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">'. check_plain($forum->description) ."</div>\n";
        }
        $description .= "</div>\n";

        $rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => '4'));
      }
      else {
        $forum->old_topics = _forum_topics_read($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">'. check_plain($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", NULL, NULL, 'new') : ''), 'class' => 'topics'),
          array('data' => $forum->num_posts, 'class' => 'posts'),
          array('data' => _forum_format($forum->last_post), 'class' => 'last-reply'));
      }
    }

    print theme('table', $header, $rows);

  }

--
When your problem is solved, please post a follow-up to the thread you started.

luyendao’s picture

Ohhh, i see. I understood intercepting drupal functions, but wasn't sure where you would get the variables and data from. It never occured to me to just copy and paste the source code. That feels so advanced ;-)

Thank you again, i hope this thread helps others. Sooner or later building a site, you get to the forums, and think, hmm, this isn't as easy as changing the way nodes look (with phptemplate).

Thanks again!

Southpaw’s picture

(Bookmarking for future reference) :)

jenlampton’s picture

I can't get it to work, wondering if 4.7 is supposed to be done differently.
Jen

vm’s picture

May want to consider the flatforum.module for D 4.7.x see: http://drupal.org/project/flatforum, which should help you with the template.php and the forum.css

jenlampton’s picture

Yes, I have flatforum installed. It was designed to theme the forum topics, not the overview page. So unfortunately, I need to get this working too.
Jen

tmichnik’s picture

Hi,

I'm trying to customize the actual headings. So for instance instead of "Post new forum topic", I want it to say "Add new message". And instead of "Created" to say "Date Posted" and so on.

I tried inserting below code in forum_list.tpl.php. I'm either inserting in the wrong location or I'm definitely doing something wrong because nothing is happening.

if (user_access('create forum topics')) {
$output .= l(t('Add new message.'), "node/add/forum/$tid");
}
else if ($user->uid) {
$output .= t('You are not allowed to post a new forum topic.') ;
}
else {
$output .= t('Login to post a new forum topic.', array('%login' => url('user/login')));
}

Can you help? or direct me somewhere for answers?

I'm new to .php, so I really don't know what I'm doing.

Thank you so much in advance.

Tatyana

summit’s picture

Interesting post, subscribing, needing forum-theme changes also on http://www.trekking-world.com/forum
greetings,
Martijn

michelle’s picture

This is a very old post and most of it isn't applicable anymore. Flatforum is dead. If you have questions about theming your forum, you're better off starting a new topic with your questions. "Subscribing" to a post that has been dead for a long time won't get you new information.

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

summit’s picture

Thanks Michelle, sometimes somebody is triggered again, but you are right, Too old posts are dead...
Greetings,
Martijn