Webmastersite.net
Register Log In

own folder graphic for each category

Comments on own folder graphic for each category

frankbeckers
Forum Regular

Usergroup: Customer
Joined: Dec 20, 2007
Location: Germany

Total Topics: 33
Total Comments: 106
Posted Jan 10, 2008 - 2:28 PM:

Hi to all,

for those who wants to have a unique folder graphic for each category here is a little solution. If you replace in main.tpl

<!-- BEGIN CATSBODY -->
<!-- BEGIN REGULAR -->
<td {CATWIDTH} valign="top" class="category">
<img src="{IMAGESURL}/folder.gif" alt="" /> <a href="{CATURL}" class="categoryname">{CATNAME}</a> ({CATNUMLINKS}) {CATHASNEW} {CATADMIN}<br />


with

<!-- BEGIN CATSBODY -->
<!-- BEGIN REGULAR -->
<td {CATWIDTH} valign="top" class="category">
<?php if (file_exists("{IMAGESPATH}/folder-{CATID}.gif")) { ?>
<img src="{IMAGESURL}/folder-{CATID}.gif" alt="{SITETITLE} - {CATNAME}" align="top" style="float:left; padding:0px 5px 0px 0px;">
<?php } else if (file_exists("{IMAGESPATH}/folder-{CATNAME}.gif")) { ?>
<img src="{IMAGESURL}/folder-{CATNAME}.gif" alt="{SITETITLE} - {CATNAME}" align="top" style="float:left; padding:0px 5px 0px 0px;">
<?php } else { ?>
<img src="{IMAGESURL}/folder.gif" alt="{SITETITLE} - {CATNAME}" align="top">
<?php } ?>
<a href="{CATURL}" class="categoryname" title="{SITETITLE} - {CATNAME}">{CATNAME}</a> ({CATNUMLINKS}) {CATHASNEW} {CATADMIN}<br />


for each category there will be used a folder grafic with the name 'folder-{CATID}.gif' or 'folder-{CATNAME}.gif'. Only if this new picture files are not present, the orginal file 'folder.gif' will be used.

All extensions or questions to this little php coding are welcome.

If you want to see it working, i can post some links (only german sites, but for picture looking it will be okay wink ).

Regards,
Frank
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Jan 11, 2008 - 11:53 AM:

What you posted will not work for 4.1, except by accident if you have leftovers from a 4.0 install not properly removed, since you had it looking for template-associated images instead of style-associated images. Fixed it for you.

Using {CATNAME} will break on non-trivial names... possibly on spaces, almost certainly on apostrophes and punctuation. Worth noting it'd be case-sensitive on *nix.

An alternate method would be a custom file field for categories.
frankbeckers
Forum Regular

Usergroup: Customer
Joined: Dec 20, 2007
Location: Germany

Total Topics: 33
Total Comments: 106
Posted Jan 11, 2008 - 6:31 PM:

Hi Paul,

thanx for your help. I thought the using of {TEMPLATESDIR} is okay cause downlevel compatibility. But now I know it was randomly correct.

But your fixed version doesn't work for me, cause {IMAGESURL} includes every time the full url and the php function file_exists does not honor 'remote' urls. So I strip down {IMAGESURL} to have a relative dir.


...
<?php if (file_exists("templates/".basename('{IMAGESURL}')."/folder-{CATID}.gif")) { ?>
<img src="{IMAGESURL}/folder-{CATID}.gif" alt="{SITETITLE} - {CATNAME}" align="top" style="float:left; padding:0px 5px 0px 0px;">
<?php } else if (file_exists("templates/".basename('{IMAGESURL}')."/folder-{CATNAME}.gif")) { ?>
<img src="{IMAGESURL}/folder-{CATNAME}.gif" alt="{SITETITLE} - {CATNAME}" align="top" style="float:left; padding:0px 5px 0px 0px;">
<?php } else { ?> <img src="{IMAGESURL}/folder.gif" alt="{SITETITLE} - {CATNAME}" align="top">
<?php } ?>
<a href="{CATURL}" class="categoryname" title="{SITETITLE} - {CATNAME}">{CATNAME}</a> ({CATNUMLINKS}) {CATHASNEW} {CATADMIN}<br />
...


Regards,
Frank
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Jan 12, 2008 - 2:10 PM:

Ah, forgot that. {IMAGESPATH} is the one for file paths.
frankbeckers
Forum Regular

Usergroup: Customer
Joined: Dec 20, 2007
Location: Germany

Total Topics: 33
Total Comments: 106
Posted Jan 13, 2008 - 6:44 AM:

Paul wrote:
Ah, forgot that. {IMAGESPATH} is the one for file paths.


That's what i'm searching for... but it is also not working, cause {IMAGEPATH} contains the full installation dir from my hoster. (like automatcly File Upload Path: is filled) and not the relativ images path.

thanx for help,
Frank

Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Jan 13, 2008 - 11:59 AM:

Why would you need a relative path? file_exists works with absolute paths, unless it's some sort of safe_mode restriction I'm unaware of.
frankbeckers
Forum Regular

Usergroup: Customer
Joined: Dec 20, 2007
Location: Germany

Total Topics: 33
Total Comments: 106
Posted Jan 13, 2008 - 1:31 PM:

thanx, you are right. file_exists works also with absolute paths. Here is the corrected coding:

...
<?php if (file_exists("{IMAGESPATH}/folder/{CATID}.gif")) { ?>
<img src="{IMAGESURL}/folder/{CATID}.gif" alt="{SITETITLE} - {CATNAME}" align="top" style="float:left; padding:0px 5px 0px 0px;" />
<?php } else if (file_exists("{IMAGESPATH}/folder/{CATNAME}.gif")) { ?>
<img src="{IMAGESURL}/folder/{CATNAME}.gif" alt="{SITETITLE} - {CATNAME}" align="top" style="float:left; padding:0px 5px 0px 0px;" />
<?php } else { ?>
<img src="{IMAGESURL}/folder/folder.gif" alt="{SITETITLE} - {CATNAME}" align="top" />
<?php } ?>
<a href="{CATURL}" class="categoryname" title="{SITETITLE} - {CATNAME}">{CATNAME}</a>
...
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



Sorry, you don't have permission to post posts. Log in, or register if you haven't yet.