Jump to content

Dynamic Content Based on Location URL


LedZepmann
 Share

Recommended Posts

Hello All,

So I've launched my first PW site: http://www.neighborhoodsewerdrain.com - yea!

Next challenge: We have an 11 county service area in south east Michigan.  My boss would like the site to function in such a way as to "localize" the site depending on where the user is located.  So, if the user clicked on a Google AdWords ad targeted at Macomb County, the URL would be "www.neighborhoodsewerdrain.com/macomb/".  From there, I'd like to pull in dynamic content specific to that region, like a local phone number, the words "Macomb County" wherever I want to drop them in the content (most likely using Hanna Code or code in the template).  Further, once the user enters through the above sample URL, I'd like to prepend "/macomb/" to the root domain as the user visits other pages, which will keep the content localized. This would be ideal so as not to have to manage 11 different versions of each page.

I've begun to experiment with URL Segments and PHP switch statements.  I'm sure it's going to get a bit more complicated than that. So, if anyone can point me in the right direction with suggestions on how to pull this off, it would be most appreciated :)

Thanks!

Link to comment
Share on other sites

Without going into too much complication, I have done something vaguely similar with a car site where you select a manufacturer or a model.

In this case I used Hanna code to help me out.

So, I might have a paragraph that says

Bring your [[vehicle]] to my gararge now! We really will love your [[vehicle]]

Then, the hanna code looks at the url and does the swap:

 if($input->urlSegment1){
                        $vehicle = str_replace("-"," ", "$input->urlSegment1");
                        $vehicle = ucwords($vehicle);
                        $titlesuffix = "{$vehicle} ";
                    }else{
                        $titlesuffix = "vehicle";
                    }
                    echo $titlesuffix;

If that segment does not exist, then it just prints out "vehicle", but if it does it prints out "audi quatro" for instance

If you go to: http://claysvehiclerepairs.uk/servicing/

Look at the menu lower down on the right.

Then click on one of the manufacturers in the grid and look at the menu again on the manufacturer page - the menu is regenerated and now adds the manufacturer name on the end - that is the URL segment that is picked up by the hanna code.

It takes a bit to get your head around, but it is perfect for localisation. But one big warning - you risk duplicate content which might not sit well with search engines. So try and be as imaginative as possible. Maybe add some variation or something.

You can even add whole specific blocks. So you can call in information from some child page somewhere that is specific to a county. Again, the URL segment and say if($county = some-name) print out this special para, else print out the default para. Or something. It does mean some extra work, but might make feel visitors and search engines loved :)

  • Like 5
Link to comment
Share on other sites

Thanks Joss,

So I placed this in my _init.php file, which makes it global and available throughout the site:

if($input->urlSegment1) {
    $localpath = str_replace("","","$input->urlSegment1");
}else{
    $localpath = "";
}

Now, in my top nav and footer menu, I place "$localpath" first after href=' :

$homepage = $pages->get('/');

$children = $homepage->children();

      foreach($children as $child) {

      if($child->id == $page->rootParent->id) {

            echo "<li class='current'><a href='$child->url$localpath'>$child->title</a></li>";
            echo "<li class='divider'></li>";
     } else {
            echo "<li><a href='$child->url$localpath'>$child->title</a></li>";
            echo "<li class='divider'></li>";
      }
}

For my top and footer logo links to home:

<a href="/<?php echo $localpath; ?>"

All works perfect. Now I can use Hanna Code to serve up local content for area specific AdWords campaigns. :cool:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...