Hallo.
Ich habe versucht, einen Loop Offset für meine Related Posts zu kreieren.
Die sind bei mir mit einem "Scrollable" Container umhüllt und ich möchte, dass die ersten 4 "Related Posts" angezeigt werden und dass man dann zu den nächsten 4 weiterscrollen kann. Insgesamt 12.
Ursprünglich sah das ganze so aus (ohne Offset):
PHP
<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"> <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> <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>
Dann hab ich folgendes versucht:
PHP
<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"> <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> </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; ?>
Leider bekomme ich Syntax-Fehler ("syntax error, unexpected T_ENDWHILE") egal wo und wie viele "closing tags" ich verwende. Ich verzweifle so langsam und hoffe, dass mir jemand weiterhelfen kann und mir meinen Fehler aufzeigen kann.
Vielen lieben Dank im Voraus! :)