Skip to content

Instantly share code, notes, and snippets.

@eri-trabiccolo
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eri-trabiccolo/aafdea95fc3b0f15d0d2 to your computer and use it in GitHub Desktop.
Save eri-trabiccolo/aafdea95fc3b0f15d0d2 to your computer and use it in GitHub Desktop.
Customizr page of posts template
<?php
/*
* Template Name: Page of Posts
*/
/* Configuration */
$design_layout = 'grid'; /* or alternate */
$show_page_title = true; /* or false */
$number_of_posts = 0; /* -1 stays for unlimited, 0 will use the Maximum number of posts per page settings */
/* bind a page to a category*/
$page_category = array();
/* or set up as
$page_category = array(
// page_id => cat_id
'38' => '1',
'40' => '7'
);*/
/* will be overridden by the setting Show metas in home (if true) if you display this tempalate in home */
$show_posts_metas = true; /* or false */
/* query parameters here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters */
$tc_posts_page_template_the_query = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $number_of_posts ? $number_of_posts : get_option('posts_per_page'),
);
/* End of configuration */
if ( array_key_exists( get_the_ID(), $page_category ) )
$tc_posts_page_template_the_query = array_merge( $tc_posts_page_template_the_query, array( 'cat' => $page_category[get_the_ID()] ) );
/* are we displaying this template in home? TODO handle pagination properly */
if ( get_queried_object_ID() == get_option( 'page_on_front' ) && get_option('show_on_front') == 'page' ){
/* display headings */
if ( method_exists('TC_headings', 'tc_set_post_page_heading_hooks') ) {
add_filter('tc_display_customizr_headings', '__return_false');
TC_headings::$instance -> tc_set_post_page_heading_hooks();
}
$_page = get_query_var('page') ? get_query_var('page') : 1;
}
if ( 'alternate' == $design_layout )
add_filter('tc_post_list_controller', '__return_true');
else{
add_filter('tc_is_grid_enabled', '__return_true');
add_filter('tc_grid_do', '__return_true');
}
if ( $show_page_title )
add_action('__before_loop', 'print_page_title', 0);
if ( $show_posts_metas )
add_filter('tc_show_post_metas', '__return_true');
add_filter('tc_content_headings_separator', '__return_false');
function print_page_title(){
?>
<header class="entry-header">
<h1 class="entry-title"><?php echo apply_filters('tc_the_title', get_the_title() ); ?></h1>
<hr class="featurette-divider __before_content">
</header>
<?php
}
add_action('__before_loop', 'tc_posts_page_template_query', 1);
add_action('__after_loop', 'tc_posts_page_template_reset_query', 9999);
function tc_posts_page_template_query() {
global $wp_query, $tc_posts_page_template_the_query, $_page, $paged;
$paged = $_page ? $_page : $paged;
$wp_query = new WP_Query(
array_merge( $tc_posts_page_template_the_query, array('paged' => $paged) )
);
}
function tc_posts_page_template_reset_query(){
global $wp_query, $wp_the_query;
$wp_query = $wp_the_query;
}
get_template_part('index');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment