mercredi 20 septembre 2017

Why if loop is causing unexpected end of file (code attached) (Wordpress)

This code is causing

Parse error: syntax error, unexpected end of file in C:\wamp64\www\pss\wp-content\themes\pss-theme\index.php on line 18

<?php 

get_header();

                    if (have_posts()) :
                    $count = 1; 
                    while (have_posts()) : the_post(); 


get_template_part ('content');

get_sidebar(); 

get_footer(); 

?>

But if I move if, count and while from index.php,

<?php 

get_header();

get_template_part ('content');

get_sidebar(); 

get_footer(); 

?>

to the top of the content template part like this:

            <?php       if (have_posts()) :
                    $count = 1; 
                    while (have_posts()) : the_post(); ?>

                <div class="post-content u-cf">
                    <?php if (has_post_thumbnail()) { ?>
                        <div class="post-thumbnail u-cf">
                            <a href="<?php the_permalink(); ?>">
                                <?php the_post_thumbnail('small-thumbnail')  ?>
                            </a>
                        </div>
                        <?php } ?>

            <h2 class="post">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                            <p class="post-info">
                                <i class="fa fa-folder-open" aria-hidden="true"></i> 
                            <?php 
                            $categories = get_the_category(); 
                            $separator = ", ";
                            $output = '';

                            if ($categories) {
                                foreach ($categories as $category) {
                                    $output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>' . $separator;
                                }
                                echo trim ($output, $separator);
                            }
                            ?>
                            |
                                <i class="fa fa-clock-o" aria-hidden="true"></i> <?php the_time('j/m/Y'); ?>
                            </p>


                <?php the_content(); ?>
                        <hr>

                        <?php   if ( 2 === $count ) { ?>
                            <div class="main-content-advert">
                                <p>Lorem ipsum</p><p>Lorem impsum</p>
                            </div>
                        <hr>
                            <?php }
                        $count++; ?>
                        </div>   
                    <?php endwhile; ?>

                <?php
                else :
                    echo '<p> No Content found</p>';

                endif; 

?>

    </article>
        </div> 

The error is not present.

Now, I understand that it has got something to do with the loop or the count?

Aucun commentaire:

Enregistrer un commentaire