show image only if exists
fdb Offline
Junior Member
**
Posts: 2
Joined: Jun 2014
Post: #1
show image only if exists
hi all, i'm a newby in mybb and php, what i'm triyng to do is to show an image only if the related file exists on the server, i modified the forumbit_depth2_forum template but the image is always added even if the file is not in the server, can you help me to understand what's wrong in the code? Thanks.

<tr>
<td class="{$bgcolor}" align="center" valign="top" width="1"><img src="{$theme['imgdir']}/{$lightbulb['folder']}.gif" alt="{$lightbulb['altonoff']}" title="{$lightbulb['altonoff']}" class="ajax_mark_read" id="mark_read_{$forum['fid']}" /></td>
<td class="{$bgcolor}" align="center" valign="top" width="1">

<?php if(file_exists("{$theme['imgdir']}/icon_{$forum['fid']}.png")) ?>
<img height="100" width="100"  src="{$theme['imgdir']}/icon_{$forum['fid']}.png"  title="" class="ajax_mark_read" />

</td>
<td class="{$bgcolor}" valign="top">
<strong><a href="{$forum_url}">{$forum['name']}</a></strong>{$forum_viewers_text}<div class="smalltext">{$forum['description']}{$modlist}{$subforums}</div>
</td>
<td class="{$bgcolor}" valign="top" align="center" style="white-space: nowrap">{$threads}{$unapproved['unapproved_threads']}</td>
<td class="{$bgcolor}" valign="top" align="center" style="white-space: nowrap">{$posts}{$unapproved['unapproved_posts']}</td>
<td class="{$bgcolor}" valign="top" align="right" style="white-space: nowrap">{$lastpost}</td>
</tr>
06-04-2014 06:15 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: show image only if exists
You can't enter PHP into templates unless you have a modification which allows you to do so.

Also, check the syntax of 'if' in PHP: http://php.net/manual/en/control-structures.if.php

My Blog
06-05-2014 12:03 PM
Find all posts by this user Quote this message in a reply
fdb Offline
Junior Member
**
Posts: 2
Joined: Jun 2014
Post: #3
RE: show image only if exists
I solved, thanks.
06-07-2014 05:08 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: