Jump to content

Calling different .html depending on which link is clicked


Recommended Posts

Hi there,

 

I've been tasked with the job of re-doing the company website from scratch and I'm having a bit of trouble with some of the logic involved as I'm not a web designer by trade. Or by any reasonable stretch of the imagination.

 

Anywhoot, what I'm struggling with is this:

 

I have laid out the website so for each of the core business units there is one php page, call it 'page x'. On page x there are two sections; a sidebar and a content section. At the top of page x there is a menu bar with a links to a different category (eg. services, products, about, contacts, etc). What I have at the moment for page x is an INCLUDE statement in each of the subsection which pulls through a html page and plops it down in the right place.

 

What I am struggling with is how to use the links at the top of the page to pull through a different html page depending on what link I click.

 

I was thinking that I could use something a couple of variables, $sidebar and $content, and then some kind of on-click function to pass a string to each of the variables and then use the INCLUDE statement to call the correct pages.

 

What I have tentatively come up with is this :

 

<a href=#><img src="/MS_Images/service_hlight.jpg" width="100" height="42" onclick=$sidebar = "OutsourceIT_Website/Managed Services/services_side.html" /></a>

 

and then:

 

<?php
include $sidebar;
?>

 

Would this work in principle? How do I go about making sure that the variable in the link is declared properly? Is there a better way to go about doing this that I am missing due to my ignorance?

 

Hope someone can help because Uncle Google is getting fed up with my vague search terms. :(

 

Ooh boy, that's probably the exact opposite of what you should do.  No website should rely on JavaScript for navigation.

 

The solution, thankfully, is fairly simple, with some caveats for security/error handling.  URLs can have query strings attached to them.  Look at the URL for this page.  It ends with 'index.php?topic=325844.0'.  The part after the question mark is the query string.  In PHP, you can grab them by using the $_GET superglobal array.  Using our current page as an example, it would look like:

 

<?php
   $topic = $_GET['topic'];
?>

 

So, simply have your main navigation have links like companysite.com/index.php?p=about.  Then, within your index.php, you could check to see if the page is set and include it:

 

<?php
   $page = $_GET['p'];

   if(!empty($p))
   {
      switch($p)
      {
         case 'About':
            include("about.html");
            break;

         case 'News':
            include("news.html");
            break;

         default:
            include("home.html"); // if the page doesn't match one of the pages you actually have, show the home content instead
            break;
      }
   }
   else
   {
      include("home.html"); // when no query string exists at all
   }
?>

 

This is just a rough sketch, but should get you on your way.  Look into .htaccess and mod_rewrite to make your URLs SEO friendly.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.