0

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.

  1. 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>.

  2. How to remove the post author from those two posts in the grid loop.

Any help appreciated.

  • You are using page-home.php instead of home.php which comes with the (v 1.0) child theme. Are you using a static home page? – Charles Clarkson Nov 15 '13 at 16:16
1

I think both issues can be solved by altering what's happening inside the loop. The code you've posted are the arguments that are used for the query. There is a while loop which then goes through the results of the query and displays them. Try to find while ($wp_query->have_posts()): $wp_query->the_post();. Between this and endwhile; the results are displayed. There you'll find echo get_the_author(). If you remove that, the author won't be displayed. You can also alter the styling of the headers there.

  • So how would you do the alterations specifically within the Genesis framework? – urok93 Nov 14 '13 at 17:04
  • I don't know the genesis framework, but if there's a query which outputs posts, there's definitely a while loop. Did you find it? It should be in the template which is used to display your page. – eskimo Nov 14 '13 at 18:52
  • 2
    The Genesis framework handles the loop in the parent theme. There are ample Genesis specific hooks to allow filters and actions to control the result of loops. You can write your own custom WP_Query, but once you get used to it, it is often easier to use Genesis to do it. The genesis_grid_loop() function came about because child theme designers found they were often creating templates that feature one or more posts and then have the rest appear in a (normal) grid of posts. – Charles Clarkson Nov 15 '13 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.