Forum Moderators: coopster

Message Too Old, No Replies

Including footer sections that change

         

seomonster

12:22 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



Hi there,

I'm an SEO guy with not a whole heep of PHP knowledge so sorry if this question seems obvious.

I have a site in PHP and the footer area is included automatically on every page (I think you call that a PHP Include?), containing some links to other pages.

I want these footer links to vary depending on the type of page that gets requested.

For example, if a product page was requested:
[mydomain.co.uk...]
I would want footer link group 'A' to be displayed. If any other page is requested, I would want footer link group 'B' to be displayed.

I'd like to know if this is possible, what is logically the best approach and how complicated is it to implement?

Many thanks in advance, you guys are awesome.

smatts9

4:20 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



You could do something like:


if($_SERVER['PHP_SELF']=='/products/product.php') {
echo 'group A links';
} else {
echo 'group B links';
}

seomonster

11:15 am on Aug 25, 2009 (gmt 0)

10+ Year Member



Hi,

Thanks you.

Let's say I want to have ALL my product pages display group A links and all other pages display group B links. All my product pages have a unique numeric identifier in the URL, for example:

[mydomain.co.uk...]

Could I use something like this?

if($_SERVER['PHP_SELF']=='/products/[1-9].php') {
echo 'group A links';
} else {
echo 'group B links';
}

Many thanks once again!

smatts9

1:19 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



Assuming only product pages are in the /products/ folder you could try:


$folder=basename(dirname(__FILE__));
if($folder=='products') {
echo 'products links';
} else {
echo 'other links';
}

jatar_k

1:43 pm on Aug 25, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



another option you have is to set a var before the include

so in the product.php page you would have
$footerlinks = 'a';

then in the footer file check if it's set and then serve content based on that var

if (!isset($footerlinks)) $footerlinks = 'def';
switch ($footerlinks) {
case 'a':
echo 'A links';
break;
case 'b':
echo 'B links';
break;
default:
echo 'some default stuff here';
break;
}

would scale a bit better if there are multiple sets and they weren't necessarily by dir, also allows a default that would show where you had no var set

seomonster

1:43 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



Thanks but what if there are other pages in the /products/ folder? Let's say the URL structure looked more like:

[mydomain.co.uk...] (product page)
[mydomain.co.uk...] (other page)

ALL product pages have purely numerical filenames. Other pages don't. Assuming this URL structure cannot change, is there another way that I can achieve what I'm looking to do in PHP?

What if the filename extension was rewritten to '.product' for all product pages? Would this help to write the required PHP script?

Many thanks (again!)

smatts9

4:27 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



You may be able to do something with regex as far as the numbers in the url go, which I am none to good with.

Are your product pages static or dynamic and what about the other ones like privacy, TOS, contact, etc.?

seomonster

4:52 pm on Aug 25, 2009 (gmt 0)

10+ Year Member



Product pages are dynamic but rewritten to look static, i.e.
[mydomain.co.uk...]

Other pages like terms, contact etc. have no dynamic functionality but are still processed by PHP/Apache.

jatar_k

5:58 pm on Aug 25, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I wouldn't end it in .product, a standard file extension is better I would think, or none at all

did you see my post above? I'm not sure why we're veering off into talking about urls.

one script probably delivers all product pages, you could include a unique footer for those pages and you'd be done.

you could set a variable in that product script that tells the template to change the links to something else, as I posted above.

if neither of those work and you want to do it by url/pagename you can but it involves matching and chopping and such, which 'could' be slower as it is more intensive, you're already rewriting the urls I imagine, plus whatever else is happening on the page, so no need to use the most intensive ways to do things

seomonster

2:29 pm on Aug 30, 2009 (gmt 0)

10+ Year Member



Makes perfect sense, many thanks.