unexpected T_ENDIF

Discussion in 'PHP' started by serenity75, Sep 7, 2011.

  1. #1
    Hi there,

    I'm a beginner and am trying to display wp_content_slider on the home page only and display the standard header on the rest of the site.

    At first it was displaying the slider then the header image underneath, now I'm getting an unexpected T_ENDIF error message for the line with "end check for featured image or standard header".

    Any help would be much appreciated!!


      
    
                <?php                // Check to see if the header image has been removed                $header_image = get_header_image();                if ( ! empty( $header_image ) ) :            ?>            <a href="<?php //echo esc_url( home_url( '/' ) ); ?>">                        <?php                if(is_front_page())                {                if(function_exists('wp_content_slider')) { wp_content_slider(); }                }                else {                    // The header image                    // Check if this is a post or page, if it has a thumbnail, and if it's a big one                    if ( is_singular() &&                            has_post_thumbnail( $post->ID ) &&                            ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ) ) &&                            $image[1] >= HEADER_IMAGE_WIDTH ) :                        // Houston, we have a new header image!                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );                    else : ?>                    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />                    <? endif; ?>                <?php endif; // end check for featured image or standard header ?>            </a>            <?php endif; // end check for removed header image ?>
    
    
    PHP:
     
    serenity75, Sep 7, 2011 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    That's an ugly piece of code

    I reformatted it to look like

    <?php                
    // Check to see if the header image has been removed                
    $header_image = get_header_image();                
    if ( ! empty( $header_image ) ) :            
        ?>            
        <a href="<?php //echo esc_url( home_url( '/' ) ); ?>">                        
        <?php                
        if(is_front_page()) {                
            if(function_exists('wp_content_slider')) { wp_content_slider(); }                
        }                
        else {                    // The header image
                            // Check if this is a post or page, if it has a thumbnail, and if it's a big one
              if ( is_singular() && has_post_thumbnail( $post->ID ) 
                      && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ) ) 
                      &&  $image[1] >= HEADER_IMAGE_WIDTH ) :                        // Houston, we have a new header image!'
        
                      echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );                    
              else : ?>                    
                  <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
              <? endif; ?>                
        <?php } // end check for featured image or standard header ?>            
        </a>            
    <?php endif; // end check for removed header image ?>
    
    PHP:
    They have mixed and matched the style for the if statements and tried to finish one off with an endif when it should have been braces.

    Try this version.
     
    sarahk, Sep 7, 2011 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    There's some short tagging - <? instead of <?php. If short tags aren't enabled on the server your code is running on, that'll throw a fatal error.
     
    Rukbat, Sep 7, 2011 IP
  4. serenity75

    serenity75 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That worked, THANK YOU!!!

    Sorry I don't know why it came up weird when I pasted it into the message... So was it just the bracket instead of the extra endif that was missing?
     
    serenity75, Sep 7, 2011 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #5
    yes, that's right.

    always happy to help our neighbours across the ditch. Just don't get too cocky with the RWC ;)
     
    sarahk, Sep 7, 2011 IP