Page Content with Gird Blog Posts
This is a custom template. At top displaying the page content and below page content showing the latest blog posts in grid style.
Create a file “template_custom.php” and add the following code. Now upload the file in your child theme folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
<?php /* Template Name: Static Content with Blog Posts */ // 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 ){ remove_action('genesis_loop', 'genesis_do_loop'); } // Add your grid loop add_action( 'genesis_after_loop', 'gd_custom_grid_loop_helper' ); remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); add_action( 'genesis_after_endwhile', 'genesis_custom_tpl_posts_nav' ); /** Add support for Genesis Grid Loop **/ function gd_custom_grid_loop_helper() { global $paged; $first_page_limit = 4 $post_per_page = $next_page_limit = 10; if ( function_exists( 'genesis_custom_loop' ) ) { if( $paged == 1 ) $post_per_page = $first_page_limit; $args = array( 'post_type' => 'post', 'showposts' => $post_per_page, 'paged' => $paged); if( $paged > 1 ) $offset = ( $next_page_limit * ( $paged - 2 ) + $first_page_limit ); if( intval( $offset ) > 0 ) $args['offset'] = $offset; //* Add even/odd post class add_filter( 'post_class', 'gd_grid_post_class' ); genesis_custom_loop($args); }else { //* Add even/odd post class add_filter( 'post_class', 'gd_grid_post_class' ); genesis_standard_loop(); } remove_filter( 'post_class', 'gd_grid_post_class' ); } function gd_grid_post_class( $classes ) { global $wp_query; $classes[] = 'one-half'; $classes[] = ($wp_query->current_post % 2 == 0) ? 'first' : ''; return $classes; } function genesis_custom_tpl_posts_nav(){ if ( 'numeric' === genesis_get_option( 'posts_nav' ) ) genesis_custom_tpl_numeric_posts_nav(); else genesis_prev_next_posts_nav(); } function genesis_custom_tpl_numeric_posts_nav() { if( is_singular() ) return; global $wp_query, $paged; //* Stop execution if there's only 1 page if( $wp_query->max_num_pages <= 1 ) return; $max = intval( $wp_query->max_num_pages ); if( $paged == 1 ): $found_posts = $wp_query->found_posts - 4; $max = $wp_query->max_num_pages = intval( ceil( $found_posts / 10 ) ) + 1; endif; //* Add current page to the array if ( $paged >= 1 ) $links[] = $paged; //* Add the pages around the current page to the array if ( $paged >= 3 ) { $links[] = $paged - 1; $links[] = $paged - 2; } if ( ( $paged + 2 ) <= $max ) { $links[] = $paged + 2; $links[] = $paged + 1; } genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div class="navigation">', 'context' => 'archive-pagination', ) ); echo '<ul>'; //* Previous Post Link if ( get_previous_posts_link() ) printf( '<li class="pagination-previous">%s</li>' . "\n", get_previous_posts_link( apply_filters( 'genesis_prev_link_text', '«' . __( 'Previous Page', 'genesis' ) ) ) ); //* Link to first page, plus ellipses if necessary if ( ! in_array( 1, $links ) ) { $class = 1 == $paged ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' ); if ( ! in_array( 2, $links ) ) echo '<li class="pagination-omission">…</li>'; } //* Link to current page, plus 2 pages in either direction if necessary sort( $links ); foreach ( (array) $links as $link ) { $class = $paged == $link ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link ); } //* Link to last page, plus ellipses if necessary if ( ! in_array( $max, $links ) ) { if ( ! in_array( $max - 1, $links ) ) echo '<li class="pagination-omission">…</li>' . "\n"; $class = $paged == $max ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max ); } //* Next Post Link if ( get_next_posts_link() ) printf( '<li class="pagination-next">%s</li>' . "\n", get_next_posts_link( apply_filters( 'genesis_next_link_text', __( 'Next Page', 'genesis' ) . '»' ) ) ); echo '</ul></div>' . "\n"; } //* Run the Genesis loop genesis(); |
Create a page (Dashboard -> Pages -> Add New ) and select “Static Content with Blog Posts” page template from template drop down. Now publish the page. That’s it.
Leave a Reply