I'm working on a design of a website, and they *just* came to me and reported that the site doesn't print out that well. DOH! Cetain pages really need to be "printable" – how hard would it be to make a printer-friendly version?
There's an easy solution with PHP coming… (I just LOVE PHP! Can you tell? LOL!)
Duplicating all the pages and formating them so they're printer friendly wouldn't be all THAT bad (although it would be a major nuisance – then again, I get paid by the hour) 😉 what WOULD be more of a concern to me – is that means duplication of content. Should they make a change to one of these pages, they'll need to make sure they make the same exact change to the printer friendly version. Yuck!
You see the problem is there's a sidebar that would need to go away to make the page print better. And luckily, everything but the main content of the site is in includes…
sooo… there's a VERY simple solution:
<?
if (!isset($print)) {
?>
…..whatever HTML should print for the "non" printer friendly version…
<? } else { ?>
…whatever HTML (if any) should print for the PRINTER friendly version…
<? } ?>
I hve that little snippet of code all over the place now… I'm even changing the background image depending on if it's to be printer friendly or not…
<?
if (!isset($print)) {
$backgroundimage = "/images/background.gif";
} else {
$backgroundimage = "/images/printerfriendlybackground.gif";
} ?>
and then I do this in the body tag:
<body background="<? echo $backgroundimage ?>" >
Then to load the printer friendly version…
I need to create a link that looks like this:
<?
if (!isset($print)) {
?>
<p><a href="<? echo $PHP_SELF ?>?print=yes">Printer friendly version</a></p>
<? } else { ?>
<p><a href="<? echo $PHP_SELF ?>">view original</a></p>
<? } ?>
If you're smart, you'll figure out a way to put that line in one of your includes so you don't have to paste that on every page… although it's STILL better than duplicating all those files!!