Skip to content

Replicate Genesis-SB logic to display posts on the home page and archives using 3 different layouts #13

@bobbingwide

Description

@bobbingwide

In the Genesis-SB theme the home page and certain archive pages display the result of the main query in three parts.

  • Hero
  • Thumbnail grid - up to 4 by 4
  • Links section

followed by a pagination block.

60 bigrams are displayed per page.

The logic I need to replicate includes a routine to rearrange the posts per page so that those with a Featured image come first.
This is genesis_sb_the_posts( $posts, $query ) which is hooked into the_posts. It's run on every page.

Note: I assume there'll be at least one featured image in a block of 60 bigrams.

Then in the loop to display the posts there's logic to check which format to use, based on the index and the number of posts which have a featured image.

function genesis_sb_do_loop() {
	$count = 0;
	$images = genesis_sb_featured_images( 1 );
	
	if ( have_posts() ) {
		while ( have_posts() ) {
			the_post();
			//do_action( 'genesis_before_entry' );
			if ( $count == 0 ) {
				genesis_sb_hero();
			} elseif ( $count < $images  ) {
				genesis_sb_images();
			} elseif ( $count == $images ) {
				printf( '<div %s>', genesis_attr( "links" ) );
				genesis_sb_after_images();
            } else {
				genesis_sb_after_images();
			}
			$count++;
		}
		echo '</div>';
		do_action( 'genesis_after_endwhile' );
	} else {
		do_action( 'genesis_loop_else' );
	}
}
  • genesis_sb_featured_images() will return 0, 4, 8, 12 or 16
  • it uses genesis_sb_full_rows() to determine this
  • genesis_sb_hero(), genesis_sb_images() and genesis_sb_after_images are the functions being replaced by the three query blocks.

Proposed solution

  • I'll implement the the_posts filter first.
  • I have to find a way of detecting which query block is being processed to determine which of the (up to 60) posts returned in the main query should be processed per block.
  • I'm going to try to override the gutenberg_render_block_core_query_loop() to either fiddle with the main query's posts or handle the loop myself.
  • The override logic will be similar to the solution for Fizzie; I've already implemented logic to override tag-cloud and template-part.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions