I have looked in the docs and done many searches of the forums, but I can't find the answer to thsi question:

How do I alter the HTML (not just the CSS) of the forum topic list page (it's the page that shows all the forum posts)? I assume I call the theme_forum_topic_list function in the template.php file, but nowhere do I see a clear description of how to do this. The PHPTemplate Handbooks do not describe the process. Any guidance would be greatly appreciated.

Comments

pwolanin’s picture

This is just a basic theme override.

Since you are using PHPtemple, just create or add to the file in the theme folder named template.php an override theme function named phptemplate_forum_topic_list or mytheme_forum_topic_list (where mytheme is the name of your theme).

see: http://drupal.org/node/11811

This page assumes that you're going to make a template file, but you can also just write the whole function like the original:
http://api.drupal.org/api/4.7/function/theme_forum_topic_list

function phptemplate_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
//this is the original (core) code- modify it to your heart's desire and place in template.php
  global $forum_topic_list_header;

  if ($topics) {

    foreach ($topics as $topic) {
      // folder is new if topic is new or there are new comments since last visit
      if ($topic->tid != $tid) {
        $rows[] = array(
          array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
          array('data' => check_plain($topic->title), 'class' => 'title'),
          array('data' => l(t('This topic has been moved'), "forum/$topic->tid"), 'colspan' => '3')
        );
      }
      else {
        $rows[] = array(
          array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
          array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),
          array('data' => $topic->num_comments . ($topic->new_replies ? '<br />'. l(format_plural($topic->new_replies, '1 new', '%count new'), "node/$topic->nid", NULL, NULL, 'new') : ''), 'class' => 'replies'),
          array('data' => _forum_format($topic), 'class' => 'created'),
          array('data' => _forum_format($topic->last_reply), 'class' => 'last-reply')
        );
      }
    }
  }

  $output .= theme('table', $forum_topic_list_header, $rows);
  $output .= theme('pager', NULL, $forum_per_page, 0);

  return $output;
} 

---
Work: BioRAFT

MrsLovely’s picture

_phptemplate_callback and an individual tpl.php file fails completely ( for all forum overrides, and indeed a custom table theme I attempted ) , can someone explain why. I've always had success using this method and the excellent reference: http://drupal.org/node/11811 for other overrides and custom themeing. I'm using 4.7.4. Very puzzling, is there a simple explanation ?

I like to have things ' tidy ' and don't like the idea of having many long custom functions sat in the template file, it also seems to go against the ' vibe ' of phptemplate engine.

stevenlyons’s picture

Thanks, but if I want to make my own forum-topic-list.tpl.php file how do I set up the callback function in template.php? The links you point to don't explain everything. I get the general idea, but how does the array in the callback work? I can see that there are a bunch of variables that need to be included ($tid, $topics, $sortby, $forum_per_page), but what is the syntax in the callback array?

function phptemplate_forum_topic_list($forum_topic_list){
   return phptemplate_callback('forum_topic_list", array('forum_topic_list' => WHAT GOES HERE?));
}

MrsLovely’s picture

for the main forum listing, but it's obviously wrong as the forum table comes up blank:
function phptemplate_forum_list($forums, $parents, $tid) {
return _phptemplate_callback('forum_list', array('forums' => $forums, 'parents' => $parents, 'tid' => $tid));
}

So I'd be grateful to know too !

stevenlyons’s picture

...and got a blank page as well.

One other question: how does one determine what HTML is being rendered by that function (Like where are the table tags?). The function is using a bunch of PHP objects--is there reference material on this??

pwolanin’s picture

stevenlyons’s picture

How do I make changes to only the table that is generated for the forum_topic_list?

pwolanin’s picture

Theme the whole forum function as we've been discussing and change the array/parameters passed into theme('table').

---
Work: BioRAFT

pwolanin’s picture

it's easier not to make a callback- just put the function above in your template.php file and work with it there

---
Work: BioRAFT

stevenlyons’s picture

Causes PHP errors.

pwolanin’s picture

hhhm, it shouldn't unless PHPtemplate is already defining that function or unless there's a typo.

Do you have other functions in template.php? If it's a new file, but sure to put a PHP tag: <?php at the beginning of the file.

---
Work: BioRAFT

stevenlyons’s picture

No php tag at the end of the code? Maybe that's the problem.

pwolanin’s picture

no ending tag is needed- better to leave it off.

---
Work: BioRAFT

MrsLovely’s picture

just copy it from the forum.module for your version.

stevenlyons’s picture

PHP error: cannot redeclare theme_forum_topic_list()

MrsLovely’s picture

add your theme name. As in:
phptemplate_forum_topic_list

pwolanin’s picture

You need to rename it as above to phptemplate_forum_topic_list.

---
Work: BioRAFT

stevenlyons’s picture

Thanks for all the help.

stevenlyons’s picture

I have looked at the API docs for theme_table and it appears that it controls all the tables in the site?
How would I modify it so that the table only changes on the Forum topic list page?

stevenlyons’s picture

For those of struggling with this stuff, I finally figured it out (no thanks to the documentation which is really just a list of the functions in Drupal...not helpful at all).

Once you have the template.tpl.php file working, here's what you can do to add IDs to the table and th tags:

function phptemplate_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
  global $forum_topic_list_header;

  if ($topics) {

    foreach ($topics as $topic) {
      // folder is new if topic is new or there are new comments since last visit
      if ($topic->tid != $tid) {
        $rows[] = array(
          array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
          array('data' => check_plain($topic->title), 'class' => 'title'),
          array('data' => l(t('This topic has been moved'), "forum/$topic->tid"), 'colspan' => '3')
        );
      }
      else {
        $rows[] = array(
          array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
          array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),
          array('data' => $topic->num_comments . ($topic->new_replies ? '<br />'. l(format_plural($topic->new_replies, '1 new', '%count new'), "node/$topic->nid", NULL, NULL, 'new') : ''), 'class' => 'replies'),
          array('data' => _forum_format($topic), 'class' => 'created'),
          array('data' => _forum_format($topic->last_reply), 'class' => 'last-reply')
        );
      }
    }
  }
//******************************the good stuff:
  $attributes=array('id'=>'forum_table');//<---this adds an ID to the table tag
//
//the next part controls the header tags <th>:
//note the use of nested arrays
//data is the actual text in the cell, the second argument defines an id for each cell
  $forum_topic_list_header=array(
	array('data'=>'Topic','colspan'=>'2', 'id'=>'th_topics'),
	array('data'=>'Replies','id'=>'th_replies'),
	array('data'=>'Created','id'=>'th_created'),
	array('data'=>'Last Reply','id'=>'th_lastreply')
	);
  $output .= theme('table', $forum_topic_list_header, $rows, $attributes);//<--added $attributes so that the table id will be picked up
  $output .= theme('pager', NULL, $forum_per_page, 0);

  return $output;
}