Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ...
- /**
- * Tweak Archive pages queries.
- * @param object $query
- * @return object
- */
- function tweak_archives( $query ) {
- // If this is a Story Type term archive page.
- if ( !is_admin() && is_tax( 'story_type' ) && $query->is_main_query() ) {
- // Exclude the latest post from the main query without braking pagination.
- $ppp = get_option( 'posts_per_page' );
- $offset = 1;
- // Detect and handle pagination...
- if ( $query->is_paged() ) {
- // Determine page query offset (offset + current page (minus one) x posts per page)
- $page_offset = $offset + ( ( $query->query_vars['paged'] - 1 ) * $ppp );
- // Apply adjust page offset
- $query->set( 'offset', $page_offset );
- } else {
- // This is the first page. Just use the offset...
- $query->set( 'offset', $offset );
- }
- }
- return $query;
- }
- add_filter( 'pre_get_posts', 'tweak_archives' );
- /**
- * Adjusting the offset pagination on the Story Type taxonomy archive.
- * @param int $found_posts
- * @param object $query
- * @return int
- */
- function adjust_offset_pagination( $found_posts, $query ) {
- $offset = 1;
- if ( !is_admin() && is_tax( 'story_type' ) && $query->is_main_query() ) {
- $found_posts = $found_posts - $offset;
- }
- return $found_posts;
- }
- add_filter( 'found_posts', 'adjust_offset_pagination', 10, 2 );
Add Comment
Please, Sign In to add comment