Support » Plugins » 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

    (@endortrails)

    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.

    How is your plugin coming along? Its not by any chance able to be used with 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.