[HOW-TO] Do dynamic linking on your website

How-to's, little tricks, tutorials, code examples (snippets) and read-me's.

[HOW-TO] Do dynamic linking on your website

Postby IBurn36360 » 26 Aug 2010, 19:31

Tools:
Any code editing software, I highly recommend the following:
Microsoft Expression web
Adobe Dreamweaver
Notepad ++

This little tutorial will show you how to make "dynamic links" on your site. This is a very useful way of making sure you never have to re-write your links again. Lets, for example, you get or change the domain name for your your site. Let also say you did linking to all of your pages like this:
Code: Select all
<li><a href="http://www.yoursubdomain.com/Games/index.php"><span>Forums</span></a></li>

This has its uses, and its problems. This is good because firstly, you know EXACTLY where this will go, and no matter what, that wont change until you change the domain, or add one. This is bad, because no matter what, that is the ONLY place that link will try to go, even if the domain name for your site changes.

OK, now that the boring introduction is out of the way, time to learn what we are going to do. First, lets learn what we are dealing with here:

1. Variables - These should be pretty self explaining, but for those who don't. This will be how we store the link, in this case, we will be storing a string value for the link.
2. includes/functions.php - This gigantic file is what we will be adding all of our variables to. This file is downloaded in the PHPbb install, and controls a LOT of variable and permission settings for users...but that is for another tutorial.
3. The links themselves - This wont be too hard or complex, but once this, and the previous two things are done, you will never have to change a link again.

OK, so to start, we will have to add our dynamic links to includes/functions.php. Open up the file and look for the following:
Code: Select all
      'U_PRIVATEMSGS'              => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox'),
      'U_RETURN_INBOX'             => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=inbox'),
      'U_POPUP_PM'                 => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=popup'),

This should be around line 4200, just for a quick search.

Now, we need to know how to add the variable, luckily, this is easy:
Code: Select all
               'U_POPUP_PM'                               => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=popup'),
  This is the name of the variable           This sets a link path by referencing the phpbb root path, where php is located


But wait, this only references to any file deeper into the phpbb folder! Luckily, there are a couple of neat little codes that will allow you to navigate anywhere.

Code: Select all
./folder/folder/folder/index.php - this takes the php root path, and then goes into three folders to find the index for that page.
../../folder/index.php - this code goes up two levels above where phpbb is located, goes into a defined folder, and links to the index.


Now that we understand how to go anywhere we want, we need to use this, so lets start out with the variable. First, on a new line, add the name of your variable in apostrophe's, or single quotations, however you want to call it. That will look like this:
Code: Select all
'GAMES INDEX' - oddly enough, this doesn't tend to work out for me.  This, in my experience, breaks the variable and causes all sorts of problems.
'GAMES_INDEX' - This is the correct way of defining the link.  Although it doesn't HAVE to be all caps, it makes the variables easier to find when you need to.


Now for the link, first type in the following code after the variable, on the same line:
Code: Select all
=> append_sid("{$phpbb_root_path}")
This does two things, the "arrow" sets the variable to take the string from the following code which is currently only calling the phpbb root path


And to define where to go, we add all of our nice directional code to "point" to the page in relation to phpbb. So, lets say we want to go to a folder called Games, in the level above phpbb, and access the index page, we would add this to the code:
Code: Select all
=> ("{$phpbb_root_path}../Games/index.php"),
The comma is important, don't forget it

So, this says to create a string for the link to your "Games" page, that, no matter what, will always be able to find where it needs to go, as long as php knows where to go. Now to actually make use for this!

Now we need to open up our /styles/yourstylename/template/overall_header.htm.

In my case, I have used ProDrop 6 for my nav bar, but you can use any nav bar, or navigation type just as easily. So, if you recall, our original link is as follows:
Code: Select all
<li><a href="http://yourdomainname.com/Games/index.php"><span>Games</span></a></li>

we will now replace the link code with the variable in BRACKETS like this:
Code: Select all
<li><a href="{GAMES_INDEX}"><span>Games</span></a></li>


This simple code change actually does two things. First, it sets a link to your page. Secondly it sets a method that will figure out where that page is in cyberspace no matter what exterior changes happen. Be sure to check that the variable in functions.php matches the variable you are trying to call in overall_header. Something as simple as trying to call {my_link} instead of {MY_LINK} can break your board.

Clear your forum cache, and watch you new links work like a charm.



EDIT: Here are all of the dynamic links for the UCP in phpbb-3.0.7
Code: Select all
      'P_OVERVIEW'            => append_sid("{$phpbb_root_path}./ucp.php?i=171.$phpEx"),
      'P_PROFILE'             => append_sid("{$phpbb_root_path}./ucp.php?i=172.$phpEx"),
      'P_BOARD_PREFS'         => append_sid("{$phpbb_root_path}./ucp.php?i=173.$phpEx"),
      'P_PRIVATE_MSGS'        => append_sid("{$phpbb_root_path}./ucp.php?i=174.$phpEx"),
      'P_USER_GROUPS'         => append_sid("{$phpbb_root_path}./ucp.php?i=175.$phpEx"),


EDIT 2: All of the Moderation Control Panel Links for phpbb-3.0.7
Code: Select all
      'MOD_MAIN'              => append_sid("{$phpbb_root_path}./mcp.php?i=139.$phpEx"),
      'MOD_MOD_QUEUE'         => append_sid("{$phpbb_root_path}./mcp.php?i=140.$phpEx"),
      'MOD_REPORTED'          => append_sid("{$phpbb_root_path}./mcp.php?i=141.$phpEx"),
      'MOD_USER_NOTES'        => append_sid("{$phpbb_root_path}./mcp.php?i=142.$phpEx"),
      'MOD_WARNINGS'          => append_sid("{$phpbb_root_path}./mcp.php?i=143.$phpEx"),
      'MOD_LOGS'              => append_sid("{$phpbb_root_path}./mcp.php?i=144.$phpEx"),
Last edited by IBurn36360 on 29 Sep 2010, 22:29, edited 12 times in total.
Leader of Alls Requiem web development.

Capability, is humanities greatest strength, and it greatest flaw. We are capable of such good, and such evil. And yet it is in the run for the both of them, that evil is indeed winning. It grows and festers, and it holds the lives of many in its grotesque grip. The few who stay from it will eventually be tainted by its filth, but try as it might, a few will never turn.
-IBurn36360
User avatar
IBurn36360    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 167
Joined: 09 Aug 2010, 12:35
Favorite Team: AReq Game Battles Te
Gender: Male
phpBB Knowledge: 7


Re: How to do dynamic linking on your website

Postby CloudLetter » 27 Aug 2010, 08:29

wow, bit more thorough than I thought it was going to be. I just wanted to say thanks. Now I've got to sit down and study your code out a little more thoroughly.
I like the basic Stars groups. You've got your Wars and you've got your Treks.
Some of my recent portfolio includes:
Find quality day cares and preschools
Daycare Software, Preschool Software
CloudLetter    
Cadet II
Cadet II
 
Posts: 22
Joined: 20 Aug 2009, 19:44
Gender: Male
phpBB Knowledge: 3

Re: How to do dynamic linking on your website

Postby IBurn36360 » 27 Aug 2010, 15:55

It isn't really my code, I took what I could learn from reading through phpbb, and copied and modified it for my purpose. I hope all of this can help you learn though.
Leader of Alls Requiem web development.

Capability, is humanities greatest strength, and it greatest flaw. We are capable of such good, and such evil. And yet it is in the run for the both of them, that evil is indeed winning. It grows and festers, and it holds the lives of many in its grotesque grip. The few who stay from it will eventually be tainted by its filth, but try as it might, a few will never turn.
-IBurn36360
User avatar
IBurn36360    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 167
Joined: 09 Aug 2010, 12:35
Favorite Team: AReq Game Battles Te
Gender: Male
phpBB Knowledge: 7

Re: How to do dynamic linking on your website

Postby wadie » 30 Aug 2010, 05:04

That's gonna take sometime for me..

Thanks.
PM me for private support or installing MODs/styles.
User avatar
wadie    
Lieutenant
Lieutenant
 
Posts: 329
Joined: 11 Mar 2010, 10:14
Gender: Male
phpBB Knowledge: 5

Re: How to do dynamic linking on your website

Postby agfvp1 » 28 Sep 2010, 19:36

Great article...have a little prob

The code -- <li><a href="{GAMES_INDEX}"><span>Games</span></a></li> -- is breaking my board. I have changed the functions.php & overall_header.html as instructed.

When I reload my original OH template, my site comes back up (which tells me thats the problem).

I am attempting to insert a direct link to my Gallery. Which is at http://www.mysite.com/gallery

Adjustments I made to code => My Overall Header File
<li class="icon-faq"><a href="{u_faq}" title="{l_faq_explain}">{L_FAQ}</a></li> -- original script (attached for placement reference)
<li><a href="{picture_gallery}"><span>GALLERY</span></a></li>

My Includes/functions.php File
'PICTURE_GALLERY' => append_sid("{$phpbb_root_path}gallery/index.$phpEx"),

Not sure what Im doing wrong...please advise
agfvp1
Crewman
Crewman
 
Posts: 4
Joined: 28 Sep 2010, 17:33
Gender: Male
phpBB Knowledge: 2

Re: How to do dynamic linking on your website

Postby IBurn36360 » 29 Sep 2010, 03:44

agfvp1 wrote:Adjustments I made to code => My Overall Header File
<li class="icon-faq"><a href="{u_faq}" title="{l_faq_explain}">{L_FAQ}</a></li> -- original script (attached for placement reference)
<li><a href="{picture_gallery}"><span>GALLERY</span></a></li>

My Includes/functions.php File
'PICTURE_GALLERY' => append_sid("{$phpbb_root_path}gallery/index.$phpEx"),

Not sure what Im doing wrong...please advise


You actually made only a small mistake, instead of calling 'PICTURE_GALLERY' with the link, you are trying to call 'picture_gallery', which does not exist.
Replace {picture_gallery} with {PICTURE_GALLERY}.

Hope that fixes it all :)

NOTE: Updated the first post with clearer information.
Leader of Alls Requiem web development.

Capability, is humanities greatest strength, and it greatest flaw. We are capable of such good, and such evil. And yet it is in the run for the both of them, that evil is indeed winning. It grows and festers, and it holds the lives of many in its grotesque grip. The few who stay from it will eventually be tainted by its filth, but try as it might, a few will never turn.
-IBurn36360
User avatar
IBurn36360    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 167
Joined: 09 Aug 2010, 12:35
Favorite Team: AReq Game Battles Te
Gender: Male
phpBB Knowledge: 7

Re: [HOW-TO] Do dynamic linking on your website

Postby agfvp1 » 29 Sep 2010, 08:35

oooh I see. OK fixed it.....& Still Nothing.

One last question - Any manipulation of the OVERALL_HEADER.html on my part is leading to my board breaking. My editor works fine with all the other files & templates. I see above they call for Notepad to be used to open file - but the data is all jumbled together & very hard on the eyes. Any recommendations? Thank You
agfvp1
Crewman
Crewman
 
Posts: 4
Joined: 28 Sep 2010, 17:33
Gender: Male
phpBB Knowledge: 2

Re: [HOW-TO] Do dynamic linking on your website

Postby IBurn36360 » 29 Sep 2010, 14:39

agfvp1 wrote:oooh I see. OK fixed it.....& Still Nothing.

One last question - Any manipulation of the OVERALL_HEADER.html on my part is leading to my board breaking. My editor works fine with all the other files & templates. I see above they call for Notepad to be used to open file - but the data is all jumbled together & very hard on the eyes. Any recommendations? Thank You


OK, notepad isnt the best, but it can work most cases. I would highly suggest DreamWeaver from macromedia or Expression Web 3 as code browsers. You can also use something like Visual Studio to browse the code, but you will not get the design preview mode of the others. If you want me to, you could also PM me you overall_header (assuming there isn't anything you dont want me to see) and I could attempt to find the problem that way.

Give me any update and I will be gladly to help.

NOTE: Both of the links to the software mentioned are now in the OP
Leader of Alls Requiem web development.

Capability, is humanities greatest strength, and it greatest flaw. We are capable of such good, and such evil. And yet it is in the run for the both of them, that evil is indeed winning. It grows and festers, and it holds the lives of many in its grotesque grip. The few who stay from it will eventually be tainted by its filth, but try as it might, a few will never turn.
-IBurn36360
User avatar
IBurn36360    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 167
Joined: 09 Aug 2010, 12:35
Favorite Team: AReq Game Battles Te
Gender: Male
phpBB Knowledge: 7

Re: [HOW-TO] Do dynamic linking on your website

Postby agfvp1 » 29 Sep 2010, 16:56

Unable to PM you, due to my newbie status...

I have uploaded the functions.php (that goes into my includes folder) & overall_header.html
They can be found at http://www.240nation.com/functions(navlink-generation).php & http://www.240nation.com/overall_header(navlink-generation).html
Tagged with the (navlink-generation) to seperate & identify modified files. Brought them up to root for easy access. Will keep temporarily until you get a chance to look at them.

Modified Code - Line 4192 in functions.php & Line 165 in overall_header

My Gallery (as stated above) which I am attempting to establish this link to is at http://www.240nation.com/gallery

Thank you very much for your time and assistance
agfvp1
Crewman
Crewman
 
Posts: 4
Joined: 28 Sep 2010, 17:33
Gender: Male
phpBB Knowledge: 2

Re: [HOW-TO] Do dynamic linking on your website

Postby IBurn36360 » 29 Sep 2010, 19:04

Code: Select all
'<li><a href="{picture_gallery}"><span>GALLERY</span></a></li>


Remove the apostrophe and that should fix one issue.

Another is if you have not called the right variable, although this will NOT break the board, it will break the link. As I cannot see functions.php (.php script language is unrecognizable to .html and is not posted into source), I am unable to determine if that is also an issue.

Tell me if this helps in any way, and I will always help as best as I can.
-IBurn36360
Leader of Alls Requiem web development.

Capability, is humanities greatest strength, and it greatest flaw. We are capable of such good, and such evil. And yet it is in the run for the both of them, that evil is indeed winning. It grows and festers, and it holds the lives of many in its grotesque grip. The few who stay from it will eventually be tainted by its filth, but try as it might, a few will never turn.
-IBurn36360
User avatar
IBurn36360    
Lt. Jr Grade
Lt. Jr Grade
 
Posts: 167
Joined: 09 Aug 2010, 12:35
Favorite Team: AReq Game Battles Te
Gender: Male
phpBB Knowledge: 7

Next

Return to Tutorials and How-Tos

Who is online

Users browsing this forum: No registered users and 8 guests