Community Forums › Forums › Archived Forums › General Discussion › 2 Queries on Blog Page, Broken Pagination
Tagged: 404, Custom Query, pagination
- This topic has 5 replies, 2 voices, and was last updated 8 years, 5 months ago by
creative.patience.
-
AuthorPosts
-
August 18, 2016 at 5:49 pm #191567
creative.patience
MemberWe have a page layout that has two queries running. For some reason, the pagination for our main query returns a "Page Not Found" when we try to navigate to page 2. We've tried different methods of offsetting the pages but no luck.
Genesis Support Recommended this: http://www.billerickson.net/code/pagination-in-a-custom-query/. This change added a loop after every entry, so we tried changing add_action( 'genesis_after_entry', 'be_galleries_loop' ) to add_action( 'genesis_loop', 'be_galleries_loop' ). It ran the loop once but the pagination was still broken.
Any help would be much appreciated.
Demo: demo.creativepatience.com/magazine/
home.php code
http://demo.creativepatience.com/magazine/// Add our first 3 featured posts add_action( 'genesis_before_content', 'cd_goh_loop', 50 ); function cd_goh_loop() { $args = array( 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'posts_per_page'=> '3', // overrides posts per page in theme settings ); $loop = new WP_Query( $args ); $count = 0; global $post; if( $loop->have_posts() ) { ?> <div class="mag-home-content"> <? // loop through posts while( $loop->have_posts() ): $loop->the_post(); $do_not_duplicate = $post->ID; if ($count == 0 ) $image_feat = genesis_get_image( 'format=url&size=home-top'); else $image_feat = genesis_get_image( 'format=url&size=box-month-image'); echo '<article class="mag '; if ($count == 0 ) echo 'feature'; elseif (($count == 1 ) || ($count == 2 )) echo 'one-third feature-next'; else echo 'teaser one-third'; if( 0 == $loop->current_post || 0 == $loop->current_post % 3 ) : echo ' first'; endif; echo '">'; printf( '<div class="home-mag-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image_feat, the_title_attribute( 'echo=0' )); printf( '<h4 class="entry-title"><a href="%s" rel="bookmark">%s</a></h4>', get_permalink(), get_the_title()); ?> <div class="entry-content"><?php if ($count == 0 ) mag_excerpt(500); else mag_excerpt(100);?></div> <? echo '</article>'; $count++; endwhile; ?> </div> <? } wp_reset_query(); } // Do the rest of the posts remove_action('genesis_loop', 'genesis_do_loop'); add_action( 'genesis_loop', 'sf_custom_loop' ); function sf_custom_loop() { global $paged; /* Excludue the first 3 posts from the main query */ $temp_featured = get_posts( array( 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'posts_per_page'=> '3' ) ); $featured_ids = wp_list_pluck( $temp_featured, 'ID' ); $query_args = array( 'post_type' => 'post', 'posts_per_page' => '7', 'paged' => $paged, 'post__not_in' => $featured_ids ); $main_query = new WP_query ($query_args); //displaying the full query of the page if ($main_query->have_posts ()) : while ($main_query->have_posts ()) : $main_query->the_post(); if ($count <= 1 ) $image_feat = genesis_get_image( 'format=url&size=home-top'); else $image_feat = genesis_get_image( 'format=url&size=box-month-image'); echo '<article class="mag post '; if ($count <= 1 ) echo 'feature'; else echo 'teaser one-half'; if( 0 == $main_query->current_post || 0 == $main_query->current_post % 2 ) : echo ' first'; endif; echo '">'; printf( '<div class="home-mag-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image_feat, the_title_attribute( 'echo=0' )); printf( '<h4 class="entry-title"><a href="%s" rel="bookmark">%s</a></h4>', get_permalink(), get_the_title());?> <div class="entry-content"><?php if ($count <= 1 ) mag_excerpt(500); else mag_excerpt(200);?></div> <? echo '</article>'; $count++; endwhile; genesis_posts_nav(); endif; wp_reset_query(); }
August 18, 2016 at 5:56 pm #191569Sridhar Katakam
ParticipantI have written about something similar in my members-only website yesterday. Take a look at the preview of https://sridharkatakam.com/categories-list-one-latest-post-rest-grid-category-archives-genesis/. Is that close to what you are trying to do?
August 18, 2016 at 6:15 pm #191571creative.patience
MemberYes, it's very similar to what we're trying to do.
August 27, 2016 at 6:18 am #192121creative.patience
MemberHello,
We've purchased membership and installed the code from your site. For some reason, it's working on our Demo site but not on the live site. We've done copies of the full theme and temporarily renamed the plugin folder on the live site, but for some reason, we still can't get page 2 to load on the live site.
Any ideas what else could be causing Page 2 to be a 404?
August 27, 2016 at 6:56 am #192123creative.patience
MemberFigured it out....The problem was that we had renamed the "blog" slug to "magazine" but had not set has_archives => 'true'.....
Once we added that, the pagination started working but it started considering the blog front page to be an archive and we lost the customizations in home.php. Duplicating home.php into archive-post.php fixed that.
There's probably a better solution (would love if someone could provide it) but this finally got it working.
August 27, 2016 at 7:18 am #192124creative.patience
MemberActually, our solution doesn't work. The offset code is no longer removing the offset posts from the query, which is probably why pagination is working....
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.