-4

My website receives this error when going to the home page: Parse error: syntax error, unexpected 'endif' (T_ENDIF) in /home/wha2wearco/wha2wear.com/wp-content/themes/pro-blogg/index.php on line 63

But I don't see that error on line 63. Actually, I don't see any error. Can anyone check the code for me, please:

<?php
get_header();
?>
<?php
    if (dess_setting('dess_show_slider') == 1) :

        $args = array(
            'post_type' => 'post',
            'meta_key' => 'show_in_slider',
            'meta_value' => 'yes',
            'posts_per_page' => -1,
            'ignore_sticky_posts' => true
            );
        $the_query = new WP_Query( $args );
        if ( $the_query->have_posts() ) :
            echo '<div class="home_slider"><ul class="slides">';
            while ( $the_query->have_posts() ) : $the_query->the_post();
                $type = get_post_meta($post->ID,'page_featured_type',true);
                switch ($type) {
                    case 'youtube':
                        echo '<li><iframe width="560" height="315" src="http://www.youtube.com/embed/'.get_post_meta( get_the_ID(), 'page_video_id', true ).'?wmode=transparent" frameborder="0" allowfullscreen></iframe></li>';
                        break;
                    case 'vimeo':
                        echo '<li><iframe src="http://player.vimeo.com/video/'.get_post_meta( get_the_ID(), 'page_video_id', true ).'?title=0&amp;byline=0&amp;portrait=0&amp;color=03b3fc" width="500" height="338" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></li>';
                        break;
                    default:
                        $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
                        echo '<li><a style="background-image: url('.$thumbnail[0].')" class="home_slide_bg" href="'.get_permalink().'"></a><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
                        break;
                }

            endwhile;
            echo '</ul></div>';
            wp_reset_postdata();
        endif;
    endif;
?>
<div class="container">
<div class="post_content">
    <div class="home_posts">
        <?php
            $args2 = array(
            'post_type' => 'post',
            'posts_per_page' => 10,
            'paged' => ( get_query_var('paged') ? get_query_var('paged') : 2),
            );
            $query = new WP_Query( $args2 );
            if ( $query->have_posts() ) :
                while ( $query->have_posts() ) : $query->the_post();
                    echo '<div class="grid_post">
                            <h3><a href="'.get_permalink().'">'.get_the_title().'</a></h3>';
                    $type = get_post_meta($post->ID,'page_featured_type',true);
                    switch ($type) {
                        case 'youtube':
                            echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/'.get_post_meta( get_the_ID(), 'page_video_id', true ).'?wmode=transparent" frameborder="0" allowfullscreen></iframe>';
                            break;
                        case 'vimeo':
                            echo '<iframe src="http://player.vimeo.com/video/'.get_post_meta( get_the_ID(), 'page_video_id', true ).'?title=0&amp;byline=0&amp;portrait=0&amp;color=03b3fc" width="500" height="338" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
                            break;
                        default:
                            echo '<div class="grid_post_img">
                                        <a href="'.get_permalink().'">'.get_the_post_thumbnail().'</a>
                                    </div>';
                            break;
                    }
                    echo '<div class="grid_home_posts">
                                <p>'.dess_get_excerpt(120).'</p>
                            </div>
                        </div>
                        ';
                endwhile;
            endif;
        ?>
</div>
<?php
    echo '<div class="load_more_content"><div class="load_more_text">';
            ob_start();
                next_posts_link('LOAD MORE',$query->max_num_pages);
                $buffer = ob_get_contents();
            ob_end_clean();
     if (!empty($buffer)) echo $buffer;
        echo'</div></div>';
    $max_pages = $query->max_num_pages;
        wp_reset_postdata();
    endif;
?>
<span id="max-pages" style="display:none"><?php echo $max_pages ?></span>
</div>
<?php get_sidebar(); ?>
<div class="clear"></div>

1
  • The error line is just where if finally breaks. The missing bracket is probably earlier in your code.
    – kaiser
    Aug 12, 2016 at 12:06

2 Answers 2

2

Isn't it the one just above <span id="max-pages" style="display:none"> ?

5
  • 2
    yes it's it. either the endif is too much or a : is missing after the "if"
    – mmm
    Aug 9, 2016 at 22:13
  • I don't think it's a : just because that would start rendering a closing HTML tag, which seems kind of messy. Not unheard of though! Aug 9, 2016 at 22:17
  • please, check the edited question. There is a "if (!empty($buffer))" just before. thanks a lot!
    – Wha2wear
    Aug 9, 2016 at 22:33
  • 1
    Then @mmm is right. (Well we both are) That if and endif aren't related unless you put in a : Aug 9, 2016 at 22:34
  • Though I can't see why you would make resetting postdata and closing your divs conditional upon your next posts link buffering. Aug 9, 2016 at 22:41
2

You have a lone endif at the end of your pagination block and then you forgot the ; here:

<span id="max-pages" style="display:none"><?php echo $max_pages ?></span>
5
  • Well spotted. I didn't look beyond the endif Aug 9, 2016 at 22:15
  • please, check the edited question. There is an if above that endif. Thank you!!
    – Wha2wear
    Aug 9, 2016 at 22:40
  • 1
    @Wha2wear I know that there is an if statement before, but it's a single line if statement (without leading :), so it has nothing to do with the following endif. Turning it into a block (so adding : after the if) wouldn't make any logical sense - in case there is no pagination you would end up with two unclosed divs and your $max_pages variable (which you use later on) wouldn't be set up. Actually, the way you have it now doesn't make much sense either so it would be a good idea to rewrite the entire block and apply the correct logic. :) Aug 9, 2016 at 23:09
  • @MateuszHajdziony thanks a lot for the comment, I thought that if statement would need the endif. It's weird because that's the original code provided by the theme developer... thank you!! :)
    – Wha2wear
    Aug 10, 2016 at 6:48
  • where do I need to put the ; in here <span id="max-pages" style="display:none"><?php echo $max_pages ?></span>? thank you!
    – Wha2wear
    Aug 10, 2016 at 6:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.