I'm ramping up on Drupal and have a "best practices" type question. I'd like to put the list of forums on the front page of a Drupal site and wondering the best way to do that. I considered adding a block to the forum module, but I know it's not a good idea to hack on files outside of the theme directory. Or, I can implement page-front.tpl.php in my theme directory, but I'm still learning about the process of writing custom snippets and the like to pull that data out.

Are there other options? Any advice is appreciated.

Comments

roopletheme’s picture

If you just want a block that lists the forum containers and topics, you probably don't need to modify a module. Just create a block and insert some php code.

Here's a crude example. Goto yoursite/admin/build/block and click on the "Add Block" button. Give your block a name, change the input format to "PHP code", and insert the following into the block body:

<?php 
  $forums = forum_get_forums();
  foreach ($forums as $forum) {
      if ($forum->container) {
         print "<br />" . l($forum->name, "forum/$forum->tid") . "<br />";
      }
      else {
         print "---" . l($forum->name, "forum/$forum->tid") . "<br />";
      }
  }
?>

In the section for page visibility settings, select "Show on only the listed pages" and enter "<front>" in the page list. Then click "Save Block".

Now select a region for the block (probably a sidebar, but it depends on the theme and where you want to display the block) and select "Save blocks".

Obviously, you'll want to style the output, replace the breaks, add some error checking, etc. You can modify the php code to insert divs with class names in the output, and then use CSS to get the look you want.

Hope this helps.

mountaineer’s picture

Yes, that does help immensely, gives me the kick-start I needed.

sepeck’s picture

If you just want a link to the forums you have some simpler alternatives. You could just make list

<ul>
<li><a href="/forum/1">stuff</a></li>
....

You could create a new menu with links to your forums. Each menu gets a block, set the block to only appear on the front page.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide