Reputation:
I have a handcoded site with a few hundred articles. My current theme follows a blue background. Of course the images are therefore, with a blue background. For future support of printable versions, I have (from first day) kept two versions of the images with the latter one having a white background. These ones has '_print' before their extensions.
Of course, the best way to create a printable version is to use a different CSS and hide headers and sidebars by 'display:none' in respective CSS.
Is there any way I can use PHP to automatically add '_print' before '.jpg' in printable versions? Or is there is any other way altogether?
Upvotes: 3
Views: 163
Reputation: 35679
You could probably do this either with PHP or with Javascript.
in PHP you could just pass a parameter like ?print=true and then write a little helper function to get the appropriate image url.
<?php
function getImageUrl(imageUrl) {
if(isset($_GET["print"])) {
return preg_replace('\.jpg$','_print\.jpg',imageUrl);
}
return imageUrl;
}
?>
Disclaimer - not a PHP dev.
Upvotes: 2
Reputation: 1044
If the php script uses the full name of the images while it is building the website, why not?
You should create something like this, if I expect your code to be like this:
echo '<img src="images/artcle_'.$aid.',jpg"/>';
You should add a new variable via $_GET or $_POST, e.g.:
$print = "";
if($_GET['print'] == "1"){
$print = "_print";
}
And later:
echo '<img src="images/artcle_'.$aid.$print.',jpg"/>';
Resulting in the print versions only being displayed if the Print param is sent.
Upvotes: 2
Reputation: 60048
<? php if ($print_page == true)
{
$append = "_print";
}
else
{
$append = "";
} ?>
<html>
<body>
<img src = "/image/image<?php echo $append?>.jpg />
</body>
</html>
by including $append in all your image links -they will auto update with the _print if required. Just set $print_page as true or false as needed if you want the page to be printable
Upvotes: 1