nickcernis
11/27/2014 - 9:41 AM

template_fwcblgpost.php

<?php
/**
 * Template Name: Full Width Content with Blog Posts
 *
 * @author Genesis Developer
 * @link http://genesisdeveloper.me/full-width-page-content-with-blog-posts
 * @license GPL-2.0+
 * @since: 0.1
 */

//* Add outreach-pro-home body class
add_filter( 'body_class', 'custom_body_class' );

function custom_body_class( $classes ) {

    $classes[] = 'fwc-blgpost';
    return $classes;

}

remove_action('genesis_loop', 'genesis_do_loop'); // Removing default loop
add_action('genesis_before_content', 'genesis_do_loop'); // Repositioning the page content

// Fix for the WordPress 3.0 "paged" bug.
$paged = 1;
if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
if ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
$paged = intval( $paged );

if( $paged > 1 ){
    // Removing Static Page content from 2nd page
    remove_action('genesis_before_content', 'genesis_do_loop');
}

// Add your grid loop
add_action( 'genesis_after_loop', 'gd_custom_grid_loop_helper' );
/** Add support for Genesis Grid Loop **/

function gd_custom_grid_loop_helper() {
    global $paged;
    $limit = 10;

    if ( function_exists( 'genesis_custom_loop' ) ) {

        if( $paged < 2 )
            $limit = 4; // showing 4 posts 

        $args = array( 'post_type' => 'post', 'showposts' => $limit, 'paged' => $paged);

        // From 2nd page displaying 10 posts
        if( $paged > 2 )
            $offset = ( 10 * ( $paged - 1 ) + 4 );
        elseif( $paged == 2 )
            $offset = 4;

        if( intval( $offset ) > 0 ) $args['offset'] = $offset;

        //* Add columns class
        add_filter( 'post_class', 'gd_grid_post_class' );

        //* Modify the ... excerpt cutoff
        add_filter( 'excerpt_more', 'sp_new_excerpt_more' );
        
        genesis_custom_loop($args);

    }	else {
        //* Add columns class
        add_filter( 'post_class', 'gd_grid_post_class' );
        genesis_standard_loop();
    }

    remove_filter( 'post_class', 'gd_grid_post_class' );
    remove_filter( 'excerpt_more', 'sp_new_excerpt_more' );
}

function gd_grid_post_class( $classes ) {

    global $wp_query;
    $classes[] = 'one-half';

    $classes[] = ($wp_query->current_post % 2 == 0) ? 'first' : '';

    return $classes;

}

function sp_new_excerpt_more() {
    return  ' ... <a href="'. esc_url( get_permalink() ) . '" class="more-link">[Continue reading]</a>';
}

//* Run the Genesis loop
genesis();