• Welcome to ForumKorner!
    Join today and become a part of the community.

Adding navigational links to your MOD (breadcrumbs)

Phpbb-Bot

Member
Reputation
0
An easy way to add navigational links to your MOD is to use an inbuilt feature of phpBB3 called “breadcrumbs” (named because it leaves a trail back to the forum index).
It only requires a few extra lines of PHP code to add a breadcrumb to your own MOD (or to your website if you are doing personal customisations). This article explains how to do so.

To understand how this works, open styles/prosilver/template/overall_header.html and find this code:
Code: Select all ‹ {navlinks.FORUM_NAME}
This section of templating code is responsible for the creation of the breadcrumbs your see at the top of your forum.

As you can see from the code, “{navlinks.U_VIEW_FORUM}” is the actual web address of the page and “{navlinks.FORUM_NAME}” is the name of the page you are linking to.
To add a breadcrumb of your own in your MOD, open the main .php file for your MOD. Then find the page_header function call in your script (you may have several of these, so you can do this to some or all of them if you wish).
Before the page_header call, add this code:
Code: Select all $template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $user->lang['MOD_INDEX'],
'U_VIEW_FORUM' => append_sid('my_mod.'.$phpEx),
));
As you can see, this templating code corresponds to the “navlinks” loop shown above in overall_header.html
It would give an output like this:

$user->lang['MOD_INDEX'] is only an example language variable, you can set this to any language variable you like (or if it is for personal use and not a MOD, a hard coded string). In the append_sid call, you also need to replace “my_mod” with whatever the name of your .php page is called. If for whatever reason you wanted to link off-site, you could do this also by hard-coding a string. (ie. ‘U_VIEW_FORUM’ => ‘http://www.example.com’,)
Another feature of the breadcrumbs is that as it is using a template loop, you can include the code repeatedly to get more links. You could also include the code inside a loop to good effect (a foreach loop would be very useful).
For instance, you could use this code:
Code: Select all$navlinks_array = array(
array(
'FORUM_NAME' => $user->lang['MOD_INDEX'],
'U_VIEW_FORUM' => append_sid('my_mod.'.$phpEx),
),

array(
'FORUM_NAME' => $user->lang['MOD_SUBPAGE'],
'U_VIEW_FORUM' => append_sid('my_mod.'.$phpEx, 's=1'),
),

array(
'FORUM_NAME' => $user->lang['MOD_SUBPAGE_2'],
'U_VIEW_FORUM' => append_sid('my_mod.'.$phpEx, 's=2'),
),
);

foreach( $navlinks_array as $name )
{
$template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $name['FORUM_NAME'],
'U_VIEW_FORUM' => $name['U_VIEW_FORUM'],
));
}
To generate an output like this:

As these examples only require PHP changes and no template changes, there is no need to purge the cache once the changes have been applied.
I hope this article has been useful.

Posted on Sun, 31 Jan 2010 04:17:17 +0000 at http://blog.phpbb.com/2010/01/31/adding-navigational-links-to-your-mod-breadcrumbs/
Comments: http://blog.phpbb.com/2010/01/31/adding-navigational-links-to-your-mod-breadcrumbs/#comments