Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (is_sticky()) : ?>
- <div class="col-md-12 box-01">
- <div class="content">
- <?php endif; ?>
- if ( is_sticky()
- && !is_paged()
- ) {
- // Add your styling here
- }
- add_action( 'pre_get_posts', function ( $q )
- {
- if ( $q->is_home() // Only target the home page
- && $q->is_main_query() // Only target the main query
- && $q->is_paged() // Only target paged pages
- ) {
- // Remove stickies
- $q->set( 'post__not_in', get_option( 'sticky_posts' ) );
- }
- });
- add_filter( 'found_posts', function( $found_posts, WP_Query $q )
- {
- if ( $q->is_home()
- && $q->is_main_query()
- && !$q->is_paged()
- ) {
- // Get the sticky posts array
- $stickies = get_option( 'sticky_posts' );
- // Get all the post ID's from the first page
- $ids = $q->posts;
- // Remove all the current ids from the current sticky posts array
- $stickies = array_diff( $stickies, $ids );
- $found_posts = $found_posts - count( $stickies );
- }
- return $found_posts;
- }, 10, 2 );
- add_action( 'pre_get_posts', function ( $q )
- {
- if ( $q->is_home()
- && $q->is_main_query()
- ) {
- $q->set( 'ignore_sticky_posts', 1 );
- $q->set( 'post__not_in', get_option( 'sticky_posts' ) );
- add_filter( 'the_posts', function( $posts, WP_Query $q )
- {
- // Only do this for the first page
- if ( $q->is_paged() )
- return $posts;
- $stickies = get_option( 'sticky_posts' );
- // Check if we have stickies
- if ( !$stickies )
- return $posts;
- $args = [
- 'posts_per_page' => count( $stickies ),
- 'post__in' => $stickies,
- ];
- $sticky_posts = get_posts( $args );
- // Merge the array
- $posts = array_merge( $sticky_posts, $posts );
- return $posts;
- }, 10, 2 );
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement