Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2005-10-20 21:26:12
- the-bhp
- Member
- Registered: 2005-10-18
- Posts: 26
Link to printer-friendly CSS
Dear TXP community, I’m using TXP for some weeks now and this forum helped me out more than once. Thanks to all involved!
I’m doing a website for a friend. It’s supposed to be a complete collection of his essays. What I’d like to implement is a link in each individual article that says something like “printer friendly version” and shows the current article with a reduced layout.
I found the articles on the style switcher plugin and the non-plugin style switcher, but these work with cookies, which is not suitable for what I want to do, I guess.
I also found a thread where Mary supposed to use an extra style sheet and “media=print”. But afaik, many people don’t know about this option, some people I know even copy web pages into MS Word and print it then, so they don’t have all the ads and menus in their hard copy.
So, how can I link to the current article with a different CSS?
The BPH
Offline
Re: Link to printer-friendly CSS
I use php. In the head I have:
<code>
<?php
$style = “<txp:css />”; // default style
if (isset($_GET[‘print’]) && $_GET[‘print’] == ‘y’) {
$style=”/textpattern/css.php?n=print”;
}
echo “<link rel=\“stylesheet\” href=\”$style\” type=\“text/css\” media=\“all\” />\n
<link rel=\“stylesheet\” href=\”/textpattern/css.php?n=print\” type=\“text/css\” media=\“print\” />\n”; ?>
</code>
And where I want the link on the webpage to appear, I have:
<code>
<a href=”
<?php echo $_SERVER[‘PHP_SELF’]; ?>
?print=y” title=“Format this page for printing”>Printer-friendly Version</a>
</code>
I’ve tested it with PHP 4.3.6 and Textpattern 4.0.1. Let me know if you have any problems.
Offline
Re: Link to printer-friendly CSS
You don’t need any of that. Printing styles are a core feature of the CSS system.
You just have to create a CSS style (using a separate file, or the built-in TXP system) and link to it accordingly to CSS standards. Like :
<code><link rel=“stylesheet” href=“mysite.tld/textpattern/css.php?n=style-for-print” type=“text/css” media=“print”/></code>
for example.
Offline
#4 2005-10-21 15:26:47
- the-bhp
- Member
- Registered: 2005-10-18
- Posts: 26
Re: Link to printer-friendly CSS
Thanks trailgirl, that’s exactly what I was looking for.
But there’s one thing that doesn’t work, it seems to be this part here:
<code><?php echo $_SERVER[‘PHP_SELF’]; ?></code>
The link always points to the index.php, no matter which page I’m looking at.
Unfortunately, I have no clue about PHP.
Do you have an idea?
PS: I’m using PHP-Version: 4.3.11 and Textpattern 4.0.1 (r888)
Last edited by the-bhp (2005-10-21 15:28:19)
Offline
Re: Link to printer-friendly CSS
PHP_SELF should work with your version of php (versions 4.1.0 and higher). I also tried it out in Textpattern r1000 from the svn.
I’ve got it working here I’m using clean urls, dont know if that makes a difference.
The printer-friendly link simply tacks on ?print=y to the end of the current filename, which it gets from PHP_SELF. There may be another way to get the filename. Let me look at it some more and I’ll see what I can come up with, or maybe someone has a suggestion.
I wish there was a plugin that did this!
Jeremie, the built-in css is great, it is very elegant, you just print from the browser,etc., but on some non-technical-oriented sites where visitors might not be aware of that feature, it can be nice to have a specific link for them. I know it is redundant but helps as a hint for some visitors.
Offline
#6 2005-10-23 21:12:24
- the-bhp
- Member
- Registered: 2005-10-18
- Posts: 26
Re: Link to printer-friendly CSS
I found a solution: instead of <code>PHP_SELF</code> I use <code>REQUEST_URI</code> and everything works perfect.
I found this explanation via Google:
http://blog.taragana.com/index.php/archive/understanding-_serverphp_self-php_self-_serverrequest_uri-and-_serverscript_name-in-php-and-when-to-use-what/
Last edited by the-bhp (2005-10-23 21:12:54)
Offline
Re: Link to printer-friendly CSS
I use an even simpler if maybe not full proof method.
At the bottom of my default (and only css) I have
<code>
/*** printer styles hide the nav column ***/
@media print{
#sidebar{display:none;}
#content{width:100%; float:none;}
body {
margin: 20px;
font-family: verdana, arial, sans-serif;
font-size: 12px !important;
color: #333;
background-color: #fff;
}</code>
Last edited by colak (2005-10-24 06:45:05)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Link to printer-friendly CSS
trailgirl wrote:
Jeremie, the built-in css is great, it is very elegant, you just print from the browser,etc., but on some non-technical-oriented sites where visitors might not be aware of that feature, it can be nice to have a specific link for them. I know it is redundant but helps as a hint for some visitors.
You could explain it in text, or add a javascript action that would simply tell the browser to print. Non need for PHP and other things.
Offline
Re: Link to printer-friendly CSS
Agreed the whole point of stylesheets is to avoid having to use proprietary technologies to implement cross-media consumption.
Sort it out, chaps! ;)
Offline
#10 2005-12-08 23:53:44
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
Re: Link to printer-friendly CSS
LOL
but the point is: people have bad experiences printing from web pages and how do they know you’ve gone to the trouble of formatting your content for print?
if they click a printer icon, see a simply formatted page on-screen and the dialog box to print, they’ve got confirmation they’re not about to run through 20 pieces of paper with whacky margins & big blank spaces
which method you use would depend on the specific site, of course…
(but I’m really with u Jeremie)
Offline
Re: Link to printer-friendly CSS
There is a method <a href=“http://www.gyros.dk/usenet/html/styleskift.shtml”>here</a>, I am now experimenting with the individual articles of my site <a href=“http://neme.org/main/275/planning-for-the-future”>here</a>
>Edit url now points to a page with the printer friendly link
Last edited by colak (2005-12-16 16:45:09)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#12 2005-12-16 13:20:41
- alexandra
- Member
- From: Cologne, Germany
- Registered: 2004-04-02
- Posts: 1,370
Re: Link to printer-friendly CSS
I just came across www.talyst.com which is a TXP driven site. The Printerfriendly Version on this site is a really nice solution: opening in an extra window. I wonder how the author (datafirm) worked it out and if it is possible to turn his solution into a plugin?
In this thread datafirm says:
The trick is this: when we detect the Print filter in the URI we have a conditional tag that will switch the print.css stylesheet to me used on media=”screen, projection” etc.
Anybody an idea?
Offline