I am creating a custom template for WordPress. I can add multiple featured images in a single post and can show them as a gallery or slider.
Everything works fine on the first post.
When I add my second post with 2 or more featured images it does not display any image at all if I have only 1 featured image it shows.
Can anyone review my code and tell me what am I missing:
EDIT
<?php /* Template Name: Home v4 */ get_template_part('/template-parts/home4_header'); ?>
<section class="background-color">
<?php query_posts('showposts=0'); ?>
<?php $i = 1; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if(($i % 4) !== 0) { ?>
<!-- Fixed width banner -->
<div class="container">
<div class="containerBox">
<!-- Multiple Featured Images Slider -->
<?php
if (class_exists('MultiPostThumbnails')) {
// Loops through each feature image and grabs thumbnail URL
$x=1; $image1_id; $image2_id; $image3_id; $image4_id; $image5_id;
while ($x<=5) {
$image_name = 'feature-image-'.$x; // sets image name as feature-image-1, feature-image-2 etc.
if (MultiPostThumbnails::has_post_thumbnail('post', $image_name)) {
$image_id = MultiPostThumbnails::get_post_thumbnail_id( 'post', $image_name, $post->ID ); // use the MultiPostThumbnails to get the image ID
$image_thumb_url = wp_get_attachment_image_src( $image_id,'small-thumb'); // define thumb src based on image ID
$image_feature_url = wp_get_attachment_image_src( $image_id,'feature-image' ); // define full size src based on image ID
$attr = array(
'rel' => $image_thumb_url[0], // sets the url for the image thumbnails size
'src' => $image_feature_url[0], // sets the url for the full image size
);
// Use wp_get_attachment_image instead of standard MultiPostThumbnails to be able to tweak attributes
$image = wp_get_attachment_image( $image_id, 'feature-image', false, $attr );
//echo $image;
if ($x == 1) {$image1_id = $image_id;}
if ($x == 2) {$image2_id = $image_id;}
if ($x == 3) {$image3_id = $image_id;}
if ($x == 4) {$image4_id = $image_id;}
if ($x == 5) {$image5_id = $image_id;}
}
$x++;
}
}; // end if MultiPostThumbnails
if (!empty($image2_id)) { ?>
<div class="multi-thumb">
<div id="ninja-slider">
<div class="slider-inner">
<ul>
<li>
<div class="slider">
<?php the_post_thumbnail('full'); ?>
</div>
</li>
<li>
<div class="slider">
<img src="<?php echo wp_get_attachment_image( $image2_id, 'feature-image', false, $attr );?>">
</div>
</li>
<?php if (!empty($image3_id)) { ?>
<li>
<div class="slider">
<img src="<?php echo wp_get_attachment_image( $image3_id, 'feature-image', false, $attr );?>">
</div>
</li>
<?php } ?>
<?php if (!empty($image4_id)) { ?>
<li>
<div class="slider">
<img src="<?php echo wp_get_attachment_image( $image4_id, 'feature-image', false, $attr );?>">
</div>
</li>
<?php } ?>
<?php if (!empty($image5_id)) { ?>
<li>
<div class="slider">
<img src="<?php echo wp_get_attachment_image( $image5_id, 'feature-image', false, $attr );?>">
</div>
</li>
<?php } ?>
</ul>
<div class="fs-icon" title="Expand/Close"></div>
</div>
</div>
</div>
<?php
unset($image1_id, $image2_id, $image3_id, $image4_id, $image5_id, $image_name, $image, $image_thumb_url, $image_feature_url);
} else { the_post_thumbnail('full'); } ?>
<!-- End Multiple Featured Images Slider -->
</div>
<div class="post-area-category container-post-color bottom-padding">
<div class="content-block w-clearfix">
<div class="category">
<h5><?php echo the_category();?></h5>
</div>
<h1 class="black mastheading-post-v3"><?php the_title(); ?></h1>
<div class="date-block-v3 w-container">
<div class="black mini-date"><?php echo get_the_date(); ?></div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>">
<div class="black mini-date">
<?php
$comments_count = wp_count_comments();
echo $comments_count->approved;
?>
</div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>">
<div class="black mini-date">14</div>
</div>
<div class="black iltalica"><?php the_excerpt(); ?></div>
<a class="a8 cta-home-category w-button" href="<?php the_permalink(); ?>">continue reading</a>
</div>
</div>
<div class="space-4 background-color"></div>
</div>
<!-- Fixed width banner -->
<?php } elseif (($i % 4) == 0) { ?>
<!-- Full width banner -->
<div class="container-fluid">
<div class="containerBox">
<div class="home-v3-full-banner">
<?php the_post_thumbnail('full'); ?>
</div>
</div>
</div>
<div class="container post-area-category container-post-color bottom-padding">
<div class="content-block w-clearfix">
<div class="category">
<h5><?php echo the_category();?></h5>
</div>
<h1 class="black mastheading-post-v3"><?php the_title(); ?></h1>
<div class="date-block-v3 w-container">
<div class="black mini-date"><?php echo get_the_date(); ?></div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>">
<div class="black mini-date">
<?php
$comments_count = wp_count_comments();
echo $comments_count->approved;
?>
</div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>">
<div class="black mini-date">14</div>
</div>
<div class="black iltalica"><?php the_excerpt(); ?></div>
<a class="a8 cta-home-category w-button" href="<?php the_permalink(); ?>">continue reading</a>
</div>
</div>
</div>
<!-- End Full width banner -->
<?php } ?>
<?php $i++; ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
</section>
<?php get_footer(); ?>
Try this code. Not tested
<?php query_posts('showposts=0'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $i = 1; ?>
Related
Let's say I have 2 styles. Style 1 and Style 2
I would like to show every odd number post in the style 1 and even number posts in style 2
Below is my template file:
<?php /* Template Name: Home v2 */ get_header(); ?>
<main role="main">
<!-- section -->
<section>
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=' . $theme_options['blog-post-per-page'] . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="tiles-block w-clearfix">
<div class="float-left">
<div class="content-block w-clearfix">
<h5 class="black travel"><?php echo the_category();?></h5>
<h1 class="black mastheading"><?php the_title(); ?></h1>
<div class="date-block w-container">
<div class="black mini-date"> <?php echo get_the_date(); ?></div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>">
<div class="black mini-date">32</div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>">
<div class="black mini-date">14</div>
</div>
<div class="black iltalica"><?php the_excerpt(); ?></div>
<a class="a8 cta w-button" href="<?php the_permalink(); ?>">continue reading</a>
</div>
</div>
<div class="float-left natural-forest">
<div class="thumb">
<?php the_post_thumbnail('full'); ?>
</div>
</div>
<img class="right-arrow" src="<?php echo get_template_directory_uri() . '/images/right-arrow.png' ?>" />
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
The code above works good. but it gives only style 1.
I already have html setup for style 2 but don't know how to implement in the code above.
This is my style2 block
<div class="tiles-block w-clearfix">
<div class="float-right">
<div class="content-block w-clearfix">
<h5 class="black photography">PHOTOGRAPHY</h5>
<h1 class="black mastheading">title test</h1>
<div class="date-block w-container">
<div class="black mini-date">October 26, 2016</div>
<img class="mini-icon" src="http://aa.com/aa.png">
<div class="black mini-date">15</div>
<img class="mini-icon" src="http://bb.com/bb.png">
<div class="black mini-date">13</div>
</div>
<div class="black iltalica">Lorem Ipsuim dolor....</div>
<a class="a8 cta w-button" href="#">continue reading</a></div>
</div>
<div class="float-left window-light">
<div class="thumb">
<img src="<?php echo get_template_directory_uri() . '/images/post2.png' ?>" />
</div>
</div>
<img class="left-arrow" src="http://cc.com/cc.png">
</div>
This will get a little messy in PHP because you'd need several if statements. You might consider naming some of the inner divs the same, and making only the outer divs different names, and doing more of the work in CSS. That said, here's how you would do it:
Set a flag that changes each time through the loop, and check the value of the flag before you output your HTML.
$style_flag = 1;
while ($wp_query->have_posts()) : $wp_query->the_post();
//check the value
if ($style_flag == 1){
// output style 1
} else {
// output style 2
}
// do everything else you need to do in the loop
// switch the value of the flag
$style_flag = $style_flag * -1;
end while;
Back to CSS for a moment, though. Check out the nth-child selector if you're not familiar with it already: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child
I have found the solution to my problem.
<?php query_posts('showposts=0'); ?>
<?php
$i = 1;
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if(($i % 2) == 0) { ?>
<div class="tiles-block w-clearfix">
<div class="float-right">
<div class="content-block w-clearfix">
<h5 class="black photography"><?php echo the_category();?></h5>
<h1 class="black mastheading"><?php the_title(); ?></h1>
<div class="date-block w-container">
<div class="black mini-date"><?php echo get_the_date(); ?></div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>">
<div class="black mini-date">32</div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>">
<div class="black mini-date">14</div>
</div>
<div class="black iltalica"><?php the_excerpt(); ?></div>
<a class="a8 cta w-button" href="<?php the_permalink(); ?>">continue reading</a></div>
</div>
<div class="float-left window-light">
<div class="thumb">
<?php the_post_thumbnail('full'); ?>
</div>
</div>
<img class="left-arrow" src="<?php echo get_template_directory_uri() . '/images/left-arrow.png' ?>">
</div>
<?php } elseif (($i % 2) !== 0) { ?>
<div class="tiles-block w-clearfix">
<div class="float-left">
<div class="content-block w-clearfix">
<h5 class="black travel"><?php echo the_category();?></h5>
<h1 class="black mastheading"><?php the_title(); ?></h1>
<div class="date-block w-container">
<div class="black mini-date"><?php echo get_the_date(); ?></div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/comment-icon.png' ?>">
<div class="black mini-date">32</div>
<img class="mini-icon" src="<?php echo get_template_directory_uri() . '/images/heart-icon.png' ?>">
<div class="black mini-date">14</div>
</div>
<div class="black iltalica"><?php the_excerpt(); ?></div>
<a class="a8 cta w-button" href="<?php the_permalink(); ?>">continue reading</a>
</div>
</div>
<div class="float-left natural-forest">
<div class="thumb">
<?php the_post_thumbnail('full'); ?>
</div>
</div>
<img class="right-arrow" src="<?php echo get_template_directory_uri() . '/images/right-arrow.png' ?>" />
</div>
<?php } ?>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
I've made a shortcode function that returns some Advanced Custom Fields depending on which repeater field is chosen. It displays correctly and in the right order however any content typed underneath the shortcode is moved outside of its <article> container element.
Here is the code:
function boxes_shortcode($atts, $content = null) {
ob_start(); ?>
<div id="boxes">
<div class="box-gutter"></div>
<div class="box-sizer"></div>
<?php while( have_rows('box_repeater') ): the_row();
$image_id = get_sub_field('link_image');
$image_size = 'box-thumbnail';
$image_array = wp_get_attachment_image_src($image_id, $image_size);
$linkImage = $image_array[0]; ?>
<?php if(get_sub_field('box_type') == "box-link"): ?>
<div class="box">
<div class="link-box">
<img src="<?php echo $linkImage; ?>" alt="<?php echo $linkImage['alt']; ?>" />
<a class="caption-wrapper" href="http://www.google.com">
<span id="link-box-content" style="background:<?php the_sub_field('link_background_colour'); ?>">
<h6 style="color:<?php the_sub_field('link_title_colour'); ?>"><?php the_sub_field('link_title'); ?></h6>
<h4 style="color:<?php the_sub_field('link_text_colour'); ?>"><?php the_sub_field('link_text'); ?></h4>
<p style="color:<?php the_sub_field('link_text_colour'); ?>" href="<?php the_sub_field('link_url'); ?>"><?php the_sub_field('link_url_text'); ?> ></p>
</span>
</a>
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-quote"): ?>
<div class="box">
<div class="quote-box">
<div class="quotation-mark"></div>
<h4><?php the_sub_field('quote'); ?></h2>
<p><?php the_sub_field('quote_source'); ?></p>
<?php the_sub_field('quote_link_text'); ?> >
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-twitter"): ?>
<div class="box">
<div class="twitter">
<a class="twitter-timeline" href="<?php the_sub_field('twitter_url'); ?>" data-widget-id="<?php the_sub_field('twitter_widget_id'); ?>" data-chrome="noheader noscrollbar nofooter noborders transparent" data-tweet-limit="<?php the_sub_field('number_of_tweets'); ?>"></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<a class="twitter-badge" href="<?php the_sub_field('twitter_url'); ?>"></a>
<div class="twitter-bottom">See more ></div>
</div>
</div>
<?php endif;
endwhile;?>
</div>
</div>
</div>
<?php
/* Get the buffered content into a var */
$sc = ob_get_contents();
ob_end_clean();
return $sc;
}
add_shortcode('boxes', 'boxes_shortcode');
Can anyone help solve this mystery? Many thanks.
You have two extra closing <div>'s in your code.
Try this:
function boxes_shortcode($atts, $content = null) {
ob_start(); ?>
<div id="boxes">
<div class="box-gutter"></div>
<div class="box-sizer"></div>
<?php while( have_rows('box_repeater') ): the_row();
$image_id = get_sub_field('link_image');
$image_size = 'box-thumbnail';
$image_array = wp_get_attachment_image_src($image_id, $image_size);
$linkImage = $image_array[0]; ?>
<?php if(get_sub_field('box_type') == "box-link"): ?>
<div class="box">
<div class="link-box">
<img src="<?php echo $linkImage; ?>" alt="<?php echo $linkImage['alt']; ?>" />
<a class="caption-wrapper" href="http://www.google.com">
<span id="link-box-content" style="background:<?php the_sub_field('link_background_colour'); ?>">
<h6 style="color:<?php the_sub_field('link_title_colour'); ?>"><?php the_sub_field('link_title'); ?></h6>
<h4 style="color:<?php the_sub_field('link_text_colour'); ?>"><?php the_sub_field('link_text'); ?></h4>
<p style="color:<?php the_sub_field('link_text_colour'); ?>" href="<?php the_sub_field('link_url'); ?>"><?php the_sub_field('link_url_text'); ?> ></p>
</span>
</a>
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-quote"): ?>
<div class="box">
<div class="quote-box">
<div class="quotation-mark"></div>
<h4><?php the_sub_field('quote'); ?></h2>
<p><?php the_sub_field('quote_source'); ?></p>
<?php the_sub_field('quote_link_text'); ?> >
</div>
</div>
<?php endif;
if(get_sub_field('box_type') == "box-twitter"): ?>
<div class="box">
<div class="twitter">
<a class="twitter-timeline" href="<?php the_sub_field('twitter_url'); ?>" data-widget-id="<?php the_sub_field('twitter_widget_id'); ?>" data-chrome="noheader noscrollbar nofooter noborders transparent" data-tweet-limit="<?php the_sub_field('number_of_tweets'); ?>"></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<a class="twitter-badge" href="<?php the_sub_field('twitter_url'); ?>"></a>
<div class="twitter-bottom">See more ></div>
</div>
</div>
<?php endif;
endwhile;?>
</div>
<!--/div>
</div-->
<?php
/* Get the buffered content into a var */
$sc = ob_get_contents();
ob_end_clean();
return $sc;
}
add_shortcode('boxes', 'boxes_shortcode');
I am trying to echo a divider within a while loop after every item except the last item. Currently I have the divider after each item.
I've found a few solutions involving mysql rows and counters but so far nothing that relates to my situation.
I am using the following code (note, this does not include an attempted solution but rather my starting point.):
<?php if( have_rows('testimonials') ): ?>
<div class="testimonials col-md-4">
<h2>What People are Saying</h2>
<?php while( have_rows('testimonials') ): the_row();
// vars
$image = get_sub_field('image');
$quote = get_sub_field('quote');
$name = get_sub_field('name');
$divider = "<div class=\"dots full\"></div>";
?>
<div class="media">
<a class="pull-left" href="#">
<?php echo '<img src="'.$image['url'].'" alt="'.$image['alt'].'" class="img-circle" style="max-width: 70px;">'; ?>
</a>
<div class="media-body">
<div class="quote">
<?php echo $quote; ?>
</div>
<div class="source">
<span><?php echo $name; ?></span>
</div>
</div>
</div>
<?php echo $divider; ?>
<?php endwhile; ?>
</div>
<?php endif; ?>
I followed #Frogs advice and added the divider before each item and then used a counter to rule out the first item.
<?php if( have_rows('testimonials') ): ?>
<?php $test_count = 0; ?>
<div class="testimonials col-md-4">
<h2>What People are Saying</h2>
<?php while( have_rows('testimonials') ): the_row();
// vars
$image = get_sub_field('image');
$quote = get_sub_field('quote');
$name = get_sub_field('name');
$divider = "<div class=\"dots full\"></div>";
if ($test_count !== 0) {
echo $divider;
}
$test_count++;
?>
<div class="media">
<a class="pull-left" href="#">
<?php echo '<img src="'.$image['url'].'" alt="'.$image['alt'].'" class="img-circle" style="max-width: 70px;">'; ?>
</a>
<div class="media-body">
<div class="quote">
<?php echo $quote; ?>
</div>
<div class="source">
<span><?php echo $name; ?></span>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
This is my WordPress loop code... :)
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php if (is_category('instagram')) {?>
<?php
$__width = '225';
$__height = '225';
?>
<div id="instagram-photos">
<a href="<?php the_permalink() ?>"class="instagram-photo">
<div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?> </div>
</a>
</div>
<?php }elseif(is_category('runway')) { ?>
<?php
$__width = '298';
$__height = '500';
?>
<div id="runway-category">
<a href="<?php the_permalink() ?>" class="runway-category-posts">
<div class="photo"><?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?><div class="runway-title"><?php the_title(); ?></div></div>
</a>
</div>
<?php } elseif(is_category('')){?>
<article <?php post_class(); ?>>
<div class="latest-posts">
<div class="latest-posts-info">
<div class="title"><h1><?php the_title(); ?><h1></div>
<div class="text">
<?php the_excerpt(); ?>
</div>
<div class="post-share">
<div class="facebook-like" style="float:left;">
<img src="<?php echo get_template_directory_uri(); ?>/images/facebook-icon.png" />
</div>
<div class="twitter-follow" style="float:left;">
<a href="http://twitter.com/share?text=<?php the_title(); ?>&url=<?php the_permalink() ?>" target="_blank" ><img src="<?php echo get_template_directory_uri(); ?>/images/twitter-icon.png" /></a>
</div>
<div class="google-share">
<a href="https://plus.google.com/share?url=<?php the_permalink() ?>" target="_blank" ><img src="<?php echo get_template_directory_uri(); ?>/images/google-icon.png" /></a>
</div>
</div>
<div class="clear"></div><div class="post-read-more">Read More</div>
<div class="clear"></div>
</div>
<div class="latest-posts-img">
<?php //echo get_the_post_thumbnail(); ?>
<?php custom_get_post_attachments(get_the_ID(), $__width, $__height, get_the_title()); ?>
</div>
<div class="clear"></div>
</div>
</article>
<?php }?>
<?php endwhile; else: ?>
<div class="content">
<p class="not-found-p">No articles found!</p>
</div>
<?php endif; ?>
As you see I have few conditions as is_category('instagram').
The thing is: I need to limit the post quantity in exact category, not at all them.
How can I do that?
i am uncertain if we can do this in a wordpress way .. but here is the workaround --
$no_of_posts = 5;
$post_counter = 0;
if(is_Category('instagram') && ($no_of_posts<=$post_counter)) {
// bunch of code
$post_counter++;
}
untested but something like could get you going
i am trying to get wordpress posts, 3 at a time, this is the code i'm using:
<?php while ( have_posts() ) : the_post() ?>
<?php if(get_post_meta($post->ID, 'feature', true) != true) {; ?>
<div class="show_col">
<?php for ($i = 1; $i <= 3; $i++) { ?>
<div class="set">
<a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img class="image" src="http://localhost/portpress/wp-content/themes/myTemp/portfolio/<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>.jpg" width="300px" alt="AUREL #<?php the_ID(); ?>" />
</a>
<?php the_content("<P class='more'> Read More » </p>"); ?>
</div>
<?php }; ?>
</div>
<?php }; ?>
<?php endwhile; ?>
i know this loop is echoing ONE post THREE times - but what i really want is this end result
<div class="show_col">
<div class="show_col"> post1 </div>
<div class="show_col"> post2 </div>
<div class="show_col"> post3 </div>
</div>
<div class="show_col">
<div class="show_col"> post4 </div>
<div class="show_col"> post5 </div>
<div class="show_col"> post6 </div>
</div>
<!-- and so on -->
i am doing this as the height of each post varies - therefore i add something like
.show_col{clear:both} so that the next three posts go under neath
i hope you could help
thanks
This is the code you need (I corrected some of your syntax):
<?php $i = 0; ?>
<?php while ( have_posts() ): the_post();?>
<?php if(get_post_meta($post->ID, 'feature', true) != true): ?>
<div class="show_col">
<?php if(($i%3) == 0): ?>
</div>
<div class="show_col">
<?php endif;?>
<div class="set">
<a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img class="image" src="http://localhost/portpress/wp-content/themes/myTemp/portfolio/<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>.jpg" width="300px" alt="AUREL #<?php the_ID(); ?>" />
</a>
<?php the_content("<P class='more'> Read More » </p>"); ?>
</div>
</div>
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
Also you seem to add a semicolon after closing the function ( }; ), don't do that, there is no need for it.