So, call me new. I am struggling to see what i have to do here. Ive been looking for hours, decided to ask you guys.
I am trying to show a link class of "gthumb" when var=1. When it is 2, i want to have no class for the link tag.
This is calling for an image to be put into lightbox for an image gallery.
<?php if ($link == '1') {?>
<a class="gthumb" href="<?php echo $img_url; ?>" title="<?php echo $img_title; ?>">
<?php elseif ($link == '2') {?>
<a href="<?php echo $img_url; ?>" title="<?php echo $img_title; ?>">
<?php endif; ?>
<img class="<?php echo $img_class; ?>" src="<?php echo $img_preview; ?>" alt="<?php echo $img_alt; ?>" title="<?php echo $img_title; ?>" />
<?php if ($link == '1,2') : ?>
</a>
<?php endif; ?>
Thank you in advance!
Change this line:
<?php if ($link == '1,2') : ?>
to:
<?php if ($link == 1 || $link == 2) : ?>
There are other (perhaps better) ways to achieve what you're trying to do, but that should fix the link at least.
Edit: oh, and, you need to change these two lines:
<?php if ($link == '1') {?>
<?php elseif ($link == '2') {?>
to:
<?php if ($link == '1') : ?>
<?php elseif ($link == '2') : ?>
This is a matter of taste, but I like to write my mixed html/php like this:
if ($link == '1')
echo '<a class="gthumb" href="'.$img_url.'" title="'.$img_title.'">';
elseif ($link == '2')
echo '<a href="'.$img_url.'" title="'.$img_title.'">';
------------------- Controller.php --------------------
<?php
$class = 'gthumb';
if($link == 1) $class = '';
/* else if, init other vars, etc */
require "View.php";
------------------- View.php ---------------------------
<?php
<a class="<?php echo $class; ?>" href="<?php echo $url; ?>"
title="<?php echo $title; ?>" />
--------------------------------------------------------