So I wanted to create two loops on my homepage. One that would display the page's own content, and then a grid loop straight beneath it for fetching the two latest posts from the 'news' category. I couldn't really find a way to do it so I hacked around until I got it working, but I'm not sure this is the right way to be doing things, can anyone tell me what improvements I can/should make to this code?
Here's a screenshot of what I have: http://s18.postimg.org/knrq6sert/2013_11_13_22_55_58.png
Theme: Metro Template: page-home.php
//* Add support for Genesis Grid Loop
//remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_grid_loop_helper' );
function child_grid_loop_helper() {
if ( function_exists( 'genesis_grid_loop' ) ) {
global $post;
// arguments, adjust as needed
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'post_status' => 'publish',
'paged' => get_query_var( 'paged' )
);
/*
Overwrite $wp_query with our new query.
The only reason we're doing this is so the pagination functions work,
since they use $wp_query. If pagination wasn't an issue,
use: https://gist.github.com/3218106
*/
global $wp_query;
$wp_query = new WP_Query( $args );
genesis_grid_loop( array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignleft post-image',
'feature_content_limit' => 0,
'grid_image_size' => 0,
'grid_image_class' => 'alignleft post-image',
'grid_content_limit' => 100,
'more' => __( '[Continue reading...]', 'genesis' ),
) );
}
}
//* Remove the post meta function for front page only
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
genesis();`
Two things I have not figured out yet.
How to change the headings of the grid loop from
<h2>
to<h3>
. I had to style the<h2>
on that screenshot so that they would be 1.5 rem rather than the default 3 rem. But ideally they would be<h3>
.How to remove the post author from those two posts in the grid loop.
Any help appreciated.
page-home.php
instead ofhome.php
which comes with the (v 1.0) child theme. Are you using a static home page?