Title: Basic if else issue for active list items
Last modified: August 19, 2016

---

# Basic if else issue for active list items

 *  [Thad Allender](https://wordpress.org/support/users/endortrails/)
 * (@endortrails)
 * [18 years ago](https://wordpress.org/support/topic/basic-if-else-issue-for-active-list-items/)
 * Hi
    I’m making a photo gallery plugin, but having troubles with the php syntax
   needed to make the first list item of the unordered list populate with an “active”
   class. Here is the code:
 *     ```
       // Start
       $count = 1;
   
       // Output each gallery item
       if ($count == 1)
       $output .=  "<li class='active'>";
       $count++;
       else {
       $output .= "<li>"; }
       ```
   
 * This is only a small part of the plugin code, but I keep getting a parse error:
   
   Parse error: syntax error, unexpected T_ELSE in
 * Thoughts?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Thad Allender](https://wordpress.org/support/users/endortrails/)
 * (@endortrails)
 * [18 years ago](https://wordpress.org/support/topic/basic-if-else-issue-for-active-list-items/#post-778389)
 * solved it….at least for my own needs:
 *     ```
       // Start
       $count = 1;
   
       // Output each gallery item
       if($count == 1)
       $output .= "<li class='active'>";
       if($count > 1)
       $output .= "<li>";
   
       // Set the link to the attachment URL
       		$link = $a_img;
       		$output .= "\t<a href=\"$link\" title=\"$title\" class=\"$a_class\" rel=\"$a_rel\">";
       	// Output image
       		$output .= "<img src=\"$img\" alt=\"$title\" />";
       	// Close link
       		$output .= "</a>";
       		$output .= "</li>
       ";
       $count++;
       ```
   
 * This doesn’t solve the parse error, but it does move the count down until the
   list item has closed, then counts, so the first item doesn’t receive the active
   state.
 *  [possy](https://wordpress.org/support/users/possy/)
 * (@possy)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/basic-if-else-issue-for-active-list-items/#post-778722)
 * How is your plugin coming along? Its not by any chance able to be used with [Galleria](http://devkick.com/lab/galleria/)?
   I’ve been trying to figure out how to get WP to output a set of images in a post/
   page as an unordered list so that I can use Galleria.
 * I’d be interested to see what your doing or have done.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Basic if else issue for active list items’ is closed to new replies.

## Tags

 * [T_ELSE](https://wordpress.org/support/topic-tag/t_else/)

 * 2 replies
 * 2 participants
 * Last reply from: [possy](https://wordpress.org/support/users/possy/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/basic-if-else-issue-for-active-list-items/#post-778722)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
