Forums

Basic if else issue for active list items (3 posts)

  1. Thad Allender
    Member
    Posted 3 years ago #

    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?

  2. Thad Allender
    Member
    Posted 3 years ago #

    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.

  3. Possy
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic