Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $args = get_sticky_query_args();
- extract( $args );
- /* loop for sticky posts */
- if ( !empty( $sticky_posts ) ) {
- $args_sticky_loop = array(
- 'posts_per_page' => $sticky_count,
- 'post__in' => $sticky_posts,
- 'orderby' => 'post__in',
- 'ignore_sticky_posts' => 1,
- 'no_found_rows' => true,
- 'cache_results' => false
- );
- $sticky_query = new WP_Query( $args_sticky_loop );
- if ( $sticky_query->have_posts() ) :
- /* start of sticky loop */
- while ( $sticky_query->have_posts() ) : $sticky_query->the_post(); ?>
- <?php get_template_part( 'content', get_post_format() ); ?>
- <?php
- endwhile; // end of sticky loop
- wp_reset_postdata();
- endif;
- }
- ?>
- <?php
- $show_loop = true;
- /* default args for normal posts loop */
- $args_loop = array(
- 'post_type' => array('post', 'careers-post'),
- 'category__in' => $page_categories,
- 'posts_per_page' => $posts_per_page,
- 'paged' => $paged
- );
- /* there are stickies */
- if ( !empty( $all_stickies ) ) {
- $args_loop['ignore_sticky_posts'] = 1;
- $args_loop['post__not_in'] = $all_stickies;
- /* sticky and/or normal posts on current page */
- if ( $paged <= $mixed_page ) {
- $args_loop['posts_per_page'] = $sticky_count;
- if ( $paged == $mixed_page ) {
- $args_loop['paged'] = 1;
- $args_loop['posts_per_page'] = $mixed_posts_per_page;
- }
- }
- /* only normal posts on current page */
- if ( $paged > $mixed_page ) {
- // calculate offset
- $posts_to_skip = $posts_per_page - $mixed_posts_per_page;
- $offset = ( ( $paged - $mixed_page ) * $posts_per_page ) - $posts_to_skip;
- //echo $offset;
- $args_loop['offset'] = $offset;
- }
- }
- query_posts($args_loop);
- /* adjust the max_num_pages variable for pagination functions (when there are sticky posts) */
- if(!empty($all_stickies)) {
- $found_posts = (isset($wp_query->found_posts) && $wp_query->found_posts) ? (int) $wp_query->found_posts : 0;
- $total_pages = ceil( (count($all_stickies) + $found_posts) / $posts_per_page);
- $wp_query->max_num_pages = $total_pages;
- }
- /* check if only sticky posts on current page */
- $show_loop = (!empty( $all_stickies ) && ( $paged < $mixed_page ) ) ? false : true;
- if ( $show_loop ) :
- /* check if there are posts */
- if ( have_posts() ) : ?>
- <!-- top pagination functions here -->
- <?php /* Start the Loop */ ?>
- <?php while ( have_posts() ) : the_post(); ?>
- <?php get_template_part( 'content', get_post_format() ); ?>
- <?php endwhile; ?>
- <?php /* End ot the Loop */ ?>
- <!-- bottom pagination functions here -->
- <?php twentytwelve_content_nav( 'nav-below' ); ?>
- <?php else : ?>
- <article id="post-0" class="post no-results not-found">
- <header class="entry-header">
- <h1 class="entry-title"><?php _e( 'No posts to display', 'twentytwelve' ); ?></h1>
- </header>
- </article><!-- #post-0 -->
- <?php endif; // end if have_posts() check ?>
- <?php endif; // end if $show_loop check ?>
- <?php if(!$show_loop) : ?>
- <!-- bottom pagination functions here-->
- <?php twentytwelve_content_nav( 'nav-below' ); ?>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement