Wednesday, February 16, 2022

링크모음

 Problem: Load links on a portion of a web page (such as the left side) while keeping other portions of a web page constant such as navigation bars, logos, page headers or banners. 링크모음


Typically this problem arises when you would like to have dynamically loaded web content running on one part of the web page while still allowing the user to browse the website via a navigation bar. Or you just don't want to keep cutting and pasting your nav bar every time you make a new page. Or you don't want to keep cutting and pasting your include code every time you add a new page.


Usually this is accomplished by using frames. But frames are not part of the W3 standard of formatting through CSS and not through sectioning your web pages. Plus I think frames are ugly!


Basically here are the steps you will be doing -


1. Create a php file "test.php"


2. Next you will write php code that will check to see if a variable passed in a html link is a certain string. If it is then it will assign a php variable a string that is the link to your first web page and if not it will pass the link to your second web page and so on.


if{$_GET['link']=="link1"{


$link = "link1.htm";


}else if($_GET['link']=="link2"){


$link = "link2.htm";


}else{


$link = "default.htm";


}


3. Then you will write your HTML code starting with head and body and in the body you will put a div element inside which you will have links. Your links will be something like "test.php?link=link1" where you will be linking to the current webpage itself and then passing a variable called "link1" which your php code checks. You can do the same to your second link.


Eg: In your first div element


a href="test.php?link=link1" > Link1


a href="test.php?link=link2" > Link2


Now you have a navigation bar with two links that link to the same php file but passing two different values.


4. Then you will make another element where you will write the php code which is passing the URL that you wanted to direct to into this div element.


Eg: In the next div element write php code


include("$link");


Now the php code will include the path to the webpage in the div element depending on what link gets clicked.


PS: Make sure you include everything in the same php file with proper php and HTML syntax. I've changed the syntax here so the code can be visible.

No comments:

Post a Comment