I want to have an offset of 4 posts for my related posts. I'm using Flowplayer's jQuery Tools Scrollable, so I want people to be able to scroll through the 4 latest posts, then the next 4 posts etc.
I tried something like that, but I keep getting error messages:
<h2>Related Posts</h2>
<!-- "previous page" action -->
<a class="prev browse left"></a>
<!-- root element for scrollable -->
<div class="scrollable" id=chained>
<!-- root element for the items -->
<div class="items">
<!-- 1-5 -->
<div>
<!-- Related Posts-->
<?php
$backup = $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args = array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 12
);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ):
?>
<div class="relatedPosts">
<?php
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(array(120,80)); ?></a>
<div class="relatedPosts_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div></div>
// if this is not the last post
// and remainder of current post plus one then divided by four is zero
// close the container and open a new one
<?php if( $my_query->current_post != ( $my_query->post_count - 1 ) && ( ( $my_query->current_post + 1 ) % 4 ) == 0 ):
?>
</div>
<div class="relatedPosts">
<?php
endif;
endwhile;
?>
</div>
<?php
endif; ?>
<?php
$post = $backup;
wp_reset_query(); ?>
<!-- end Related Posts-->
</div>
<!-- 6-10 -->
<div>
<!-- Related Posts-->
<!-- end Related Posts-->
</div>
</div>
</div>
<!-- "next page" action -->
<a class="next browse right"></a>
<br clear="all" />
</div>
<div class="postBoxMidInner">
<?php comments_template(); ?>
</div>
</div>
<div class="postBoxBottom"></div>
</div>
<?php endwhile; else: ?>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
The error I get is the following:
Parse error: syntax error, unexpected T_ENDWHILE in /hermes/bosweb25a/b155/ipg.zoomingjapancom/wp-content/themes/alltuts-child/single.php on line 165
Line 165:
<?php endwhile; else: ?>
EDIT: This is my original setup without the offset (just the same loop twice). This works fine without any errors:
<h2>Related Posts</h2>
<!-- "previous page" action -->
<a class="prev browse left"></a>
<!-- root element for scrollable -->
<div class="scrollable" id=chained>
<!-- root element for the items -->
<div class="items">
<!-- 1-5 -->
<div>
<!-- Related Posts-->
<?php
$backup = $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>4, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="relatedPosts"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(array(120,80)); ?></a>
<div class="relatedPosts_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div></div>
<?php
}
echo '';
}
}
$post = $backup;
wp_reset_query();
?>
<!-- end Related Posts-->
</div>
<!-- 10-15 -->
<div>
<!-- Related Posts-->
<?php
$backup = $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>4, // Number of related posts that will be shown.
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<div class="relatedPosts"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(array(120,80)); ?></a>
<div class="relatedPosts_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div></div>
<?php
}
echo '';
}
}
$post = $backup;
wp_reset_query();
?>
<!-- end Related Posts-->
</div>
Here's the whole single.php: http://pastebin.com/x2mbQUFM
I cannot seem to spot the mistake and hope somebody can help me out here. Thanks a lot in advance!