Getting really frustrated with determining how to build URL’s in my website.
Here is my problem(s)…
I have a top menu bar (with dropdown sub-menus) that I want to link up to different pages in my website. Top menu items represent “categories” and so they will always link to some section landing page (e.g. Business, Sports, Politics). Sub-menu items may link to a single page (e.g. Job Listings) or to another landing page which contains a listing of things (e.g. Current News Articles).
I am looking for a stream-lined way to put all of these file paths and filenames in my HTML and make it so that it is easy to read and easy to maintain.
Below is some mock-up code which isn’t too bad, but if I give my filenames real names (e.g. “OCCoupleAccusedOfStealing$130MillionFromBanks.html”) and have some long filepath, then things could get nasty quickly?!
I could defintely use some suggestion here!
<?php
$title=$content='';
if (isset($_GET['article'])) {
$articleFile = preg_replace('#[^A-z0-9_\\-]#', '', $_GET['article']).'.php';
if(file_exists($articleFile)) {
include(articles/$articleFile);
}else{
$title = 'Article Not Found';
$content = '';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Content Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/pagelayout.css">
<link type="text/css" rel="stylesheet" href="css/dropdown.css">
</head>
<body>
<div id="wrapper" class="clearfix">
<div id="inner">
<div id="header">
<!-- DROP-DOWN MENU -->
<ul id="topMenu">
<li class="current"><a href="/articles/?article=article1">Article 1</a></li>
<li><a href="/articles/?article=article2">Article 2</a></li>
<li><a href="/articles/?article=article3">Article 3</a></li>
<!-- and so on... -->
</ul><!-- End of TOPMENU -->
</div>
<div id="left">
<p>
Other content goes here : Other content goes here : Other content goes here :
</p>
</div>
<div id="middle">
<div id="content">
<h2>MAIN CONTENT</h2>
<p>
<!-- Dynamically insert Article here using PHP include!! -->
<?php echo $content; ?>
</p>
</div>
</div>
<div id="right">
<p>
Adverting goes here : Adverting goes here : Adverting goes here :
</p>
</div>
</div>
<div id="l"></div>
<div id="r"></div>
</div>
<div id="footer">
<p>footer</p>
</div>
</body>
</html>
Also, when I put my articles in a sub-directory called “articles” it broke my code above?! I think the problem is that I am working in an IDE and so the path is funky, but maybe my modified code above wouldn’t evenwork if I have this on the internet?
Again, I think I need to get a better handle on how I build my URLs…
Thanks,
Debbie