• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

2 Queries on Blog Page, Broken Pagination

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › 2 Queries on Blog Page, Broken Pagination

This topic is: not resolved

Tagged: 404, Custom Query, pagination

  • This topic has 5 replies, 2 voices, and was last updated 6 years, 9 months ago by creative.patience.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • August 18, 2016 at 5:49 pm #191567
    creative.patience
    Member

    We 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

    // 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();
    }
    http://demo.creativepatience.com/magazine/
    August 18, 2016 at 5:56 pm #191569
    Sridhar Katakam
    Participant

    I 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?


    Genesis Tutorials | Follow me on Twitter

    August 18, 2016 at 6:15 pm #191571
    creative.patience
    Member

    Yes, it's very similar to what we're trying to do.

    August 27, 2016 at 6:18 am #192121
    creative.patience
    Member

    Hello,

    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 #192123
    creative.patience
    Member

    Figured 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 #192124
    creative.patience
    Member

    Actually, 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....

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble