Drupal Tip #8: Hide Specific Forum Containers

After a long time, the Drupal Tips are back, with a new series of 4 tips. We hope you'll enjoy them.

When you support a large forum community, which could contain dozens of categories (in the Drupal terminology, they are called container), it is not always relevant to
display all of them in the main forum index page. This could be easily customized using one of the existing forum preprocessor.

Hidden Forum Sections
  1. To achieve this, you simply need to modify your template.php file:


     * @param $variables
    function yourtheme_preprocess_forum_list(&$variables) {
    	// Remove forum containers & forum that are related to reviews for the Discussion Root
    	// See page-forum.tpl.php
    	if (count($variables["parents"]) == 0) {
    		$forum_container_ids = array(12, 30, 40); // Ids of the container you want to hide
    		foreach($variables['forums'] as $id => $forum) {
    			if (in_array($id, $forum_container_ids)) {
    			if (in_array($forum->parents[0], $forum_container_ids)) {

    In this snippet, $forum_container_ids contains the Drupal identifiers of forum containers you want to hide. You can obtain these ids in the Forum Administration page, by hovering the Edit Container buttons and see the related URL: e.g. in admin/content/forum/edit/container/40 the container id is 40.

  2. Remark: This hack works to hide anything. You can also hide forum section using this trick: the only thing you need to do is to get the related ids, by hovering the Edit Forum button: for example, the forum URL admin/content/forum/edit/forum/226 stands for forum id 226.

    It is even possible to filter them on other pages, by comparing the content of the $variables["parents"]. In our example above, we ensure that the total of parents equals to 0, to only apply the filtering at the root of the hierarchy, i.e. the index page. This could be for example relevant if you want to restrict some part to specific user groups (roles), but it will obviously require additional security checks.

This is applied in our forum for hiding support sections, which are too big and complete. These sections are however displayed as simple links at the bottom of the forum list.

  Top Top