Forum rules

Please read our Guide to Making Ozzu Tutorials if you would like to submit your own tutorials.

phpBB Dynamic Navigation Menu Mod

  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7127
  • Loc: Ozzuland
  • Status: Online

Post July 12th, 2009, 9:28 pm

Introduction


Are you using phpBB forum and want to create a menu that consists of all the forums of the site categorized correctly under their respective categories? Well, this would be your solution.

I made this for phpBB Version 3.0.5 but I'm sure that it would work for earlier versions as well.

The Instructions


Open functions.php

Find:
Code: [ Download ] [ Select ]
        $user_lang = substr($user_lang, 0, strpos($user_lang, '-x-'));
    }
  1.         $user_lang = substr($user_lang, 0, strpos($user_lang, '-x-'));
  2.     }

After that, add:
Code: [ Download ] [ Select ]
   // Generating the forum's navigation
    $sql = 'SELECT * FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC';
    $result = $db->sql_query($sql);
    while($row = $db->sql_fetchrow($result))
    {
        $template->assign_block_vars('forum_links', array(
            'IS_CATEGORY'           => ($row['parent_id'] == 0) ? true : false,
            'FORUM_NAME'            => $row['forum_name'],
            'FORUM_LINK'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
        );
    }
    $db->sql_freeresult($result);
  1.    // Generating the forum's navigation
  2.     $sql = 'SELECT * FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC';
  3.     $result = $db->sql_query($sql);
  4.     while($row = $db->sql_fetchrow($result))
  5.     {
  6.         $template->assign_block_vars('forum_links', array(
  7.             'IS_CATEGORY'           => ($row['parent_id'] == 0) ? true : false,
  8.             'FORUM_NAME'            => $row['forum_name'],
  9.             'FORUM_LINK'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
  10.         );
  11.     }
  12.     $db->sql_freeresult($result);


The Template


To make this as dynamic as possible and to help create the code able to work with any template, I would only give you the HTML list of links which you should add CSS to... if you can't/don't know how, PM me and I'll try to help you out in that field.

Anyway, what you should do to actually get the link list to show up is put the following in an HTML template file found in styles/{TEMPLATE_NAME}/template/ where the underlined text is the name of the template you are using.

Put this code anywhere wherever you want to links to appear:
Code: [ Download ] [ Select ]
<!-- BEGIN forum_links -->
<li<!-- IF forum_links.IS_CATEGORY --> class="head"<!-- ENDIF -->><!-- IF forum_links.IS_CATEGORY -->{forum_links.FORUM_NAME}<!-- ELSE --><a href="{forum_links.FORUM_LINK}">{forum_links.FORUM_NAME}</a><!-- ENDIF --></li>
<!-- END forum_links -->
  1. <!-- BEGIN forum_links -->
  2. <li<!-- IF forum_links.IS_CATEGORY --> class="head"<!-- ENDIF -->><!-- IF forum_links.IS_CATEGORY -->{forum_links.FORUM_NAME}<!-- ELSE --><a href="{forum_links.FORUM_LINK}">{forum_links.FORUM_NAME}</a><!-- ENDIF --></li>
  3. <!-- END forum_links -->


Almost a SPAM


To see this in action, you can view my forum and look at the left navigation... this is how that is created.

Conclusion


No, needless to say, you know how to get a dynamically updated list of navigation. This solution might not be suitable for huge forums (as in a forum that has so many forums, the navigation would be endless :lol: )
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 12th, 2009, 9:28 pm

  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7127
  • Loc: Ozzuland
  • Status: Online

Post July 13th, 2009, 3:25 pm

By the way, I forgot to put that in the tutorial above (and I didn't want to edit it so it would wait longer in the validation list), but I have that working on phpBB version 3.0.5... I'm sure it would work for earlier versions as well... you try that... not much changing if it doesn't work :D
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post Information

  • Total Posts in this topic: 2 posts
  • Moderator: Tutorial Writers
  • Users browsing this forum: No registered users and 2 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.