Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Is it possible to display icons next to files?
Paths in style sheets are relative to the style sheet itself (/dev2/textpattern/ it that case).
Last edited by wet (2006-04-03 04:25:52)
Offline
Re: Is it possible to display icons next to files?
thanks alot for your help guys it seems to be working now,
Cheers
Last edited by sekhu (2006-04-03 14:04:48)
Offline
Re: Is it possible to display icons next to files?
Wet,
You are the man of the hour!
That’s a great technique.
I have often assigned the file a category and then played with the form to read:
<code>
<li class=”<txp:file_download_category />”>some text</li>
</code>
along with :
<code>
li.pdf { background: url(pdf.jpg) no-repeat 0 50%; }
li.mp3 { background: url(mp3.jpg) no-repeat 0 50%; }
li.doc { background: url(doc.jpg) no-repeat 0 50%; }
</code>
Your example is far more adaptable!
Consider it bookmarked!
- I am Squared Eye and I
am launchinghave launched Pattern Tap
Offline
#16 2006-04-04 00:48:15
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
Re: Is it possible to display icons next to files?
there’s also this plugin: mrz_file_preview … but wet’s solution may be more efficient
Offline
#17 2006-04-05 22:10:48
- alannie
- Member
- From: Minnesota, USA
- Registered: 2005-09-15
- Posts: 150
Re: Is it possible to display icons next to files?
wet wrote:
<code><p class="
<txp:php>
$fn = file_download_name(); # read download filename
$ext = explode('.', $fn); # split at dot
$ext = $ext[1]; # assume second part is extension, a file type
echo $ext.'-icon">' # build class name, e.g. "foo-icon"
</txp:php>
<txp:file_download_name /></p></code>
Wet, thanks for the great suggestion! I needed exactly the file-type icon setup
that you described. I'm having a bit of trouble with the code above, though.
When I put it in, this error message gets generated in the HTML:
<p class="
<pre>tag_error <b><txp:php></b> -> <b> Warning: Missing argument 1 for file_download_name(), called in [..]: eval()'d code on line 2 and defined on line 2081</b></pre>doc-icon">
Analysis Request Form.doc</p>
Any ideas? (sorry for the formatting of this post, it was the only way I could
get both !@#$ snippets of code to show up).
Offline
Re: Is it possible to display icons next to files?
I have to admit that I wrote this code sequence out of my head, without reality check. The correct way of invoking tag handlers has to include the attribute array, even if it is empty, and my ommision of that is causing the error messge you are experiencing now.
So please use this amended sequence instead of the one I originally posted above. It also cares for filenames with more than one dot (e.g. “podcast-2006.10.01.mp3”) and uses the part after the last dot to designate the file type:
<p class="
<txp:php>
$fn = file_download_name( array () );
$ext = explode('.', $fn);
$ext = $ext[ count($ext) - 1 ];
echo $ext.'-icon">';
</txp:php><txp:file_download_name /></p>
(The original post is correct now for the sake of posterity)
HTH,
Robert
Offline
#19 2006-04-06 15:54:05
- alannie
- Member
- From: Minnesota, USA
- Registered: 2005-09-15
- Posts: 150
Re: Is it possible to display icons next to files?
Robert, that works great! Just one minor correction to the CSS: <code>background-image</code> should be <code>background</code>. Again, thanks for the great technique.
Offline
Re: Is it possible to display icons next to files?
Ah, yes. Corrected. I should stop dreamweaving my style sheets… But, then again I’m just too lazy (I think I suffer from “programmer’s disease”).
Offline
#21 2006-06-19 19:30:18
- alannie
- Member
- From: Minnesota, USA
- Registered: 2005-09-15
- Posts: 150
Re: Is it possible to display icons next to files?
Hi Robert, I am wondering if the PHP code you provided is compatible with PHP 4.3.10? I had it working on my machine, but when I uploaded it to the web host, it stopped working and I can’t figure out why. Or, does it have to do with register globals being off?
Offline
Re: Is it possible to display icons next to files?
I really haven’t got a clue. All used functions (i.e. explode
) are part of PHP 3 and better, I cannot see any globals, so it must work. Please double-check spelling, presence of graphic files in correct directories and all the other common “brain 2.0 beta” mistakes.
Offline
#23 2006-06-19 21:04:47
- alannie
- Member
- From: Minnesota, USA
- Registered: 2005-09-15
- Posts: 150
Re: Is it possible to display icons next to files?
Please double-check spelling, presence of graphic files in correct directories and all the other common “brain 2.0 beta” mistakes.
Thanks, I looked at the HTML output and none of the HTML is getting generated by the PHP. So I know it is not a misplaced image issue. I also had exactly the same code working successfully on another server, so that rules out any misspellings. I’m not sure what else to check. :/
Offline
Re: Is it possible to display icons next to files?
PHP allowed (prefs?)
Offline