Hide Specific Forum Containers

steve.56

Beta member
Messages
4
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.

To achieve this, you simply need to modify your template.php file:
template.php

/**
*
* @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)) {
unset($variables['forums'][$id]);
}

if (in_array($forum->parents[0], $forum_container_ids)) {
unset($variables['forums'][$id]);
}

}
}
}
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.

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.
 
Microsoft is said to be bringing a bigger focus to PC gaming in the next version of Windows. Citing anonymous sources, TechRadar reported yesterday that PC gaming will be part of a "new push" by Microsoft, as well as a "key component f...
 
Back
Top Bottom