Last active
November 20, 2018 03:59
-
-
Save damiencarbery/23d06e4bdd860101015cc53a05bf60ec to your computer and use it in GitHub Desktop.
Override Genesis front page template with code - Revert to a standard loop on the home page, overriding the theme front-page.php template without editing it. https://www.damiencarbery.com/2018/11/override-genesis-front-page-template-with-code/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CaitrionaCooks/Foodie Pro | |
Plugin URI: https://www.damiencarbery.com/ | |
Description: Customise Foodie Pro for CaitrionaCooks.com. | |
Author: Damien Carbery | |
Author URI: https://www.damiencarbery.com | |
Version: 0.2 | |
*/ | |
add_action( 'pre_get_posts', 'cc_front_page_change_posts_per_page' ); | |
function cc_front_page_change_posts_per_page( $query ) { | |
if ( is_front_page() ) { | |
// Display only 5 posts on home page. | |
$query->set( 'posts_per_page', 5 ); | |
return; | |
} | |
} | |
// Change home page to not use widget areas. | |
add_action( 'genesis_meta', 'cc_front_page_loop_correction', 15 ); | |
function cc_front_page_loop_correction() { | |
if ( is_front_page() ) { | |
add_action( 'genesis_loop', 'genesis_do_loop' ); | |
remove_action( 'genesis_loop', 'foodie_pro_home_loop_helper' ); | |
// Exclude post date. | |
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); | |
// Exclude 'Filed Under' category info. | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
// Replace genesis_do_post_image() with function to get centre aligned, medium sized image. | |
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); | |
add_action( 'genesis_entry_content', 'cc_front_page_post_image', 8 ); | |
// Change from excerpt to content limit. | |
remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); | |
add_action( 'genesis_entry_content', 'cc_front_page_content_limit' ); | |
// Change to do Prev/Next pagination instead of numeric as it is elsewhere. | |
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); | |
add_action( 'genesis_after_endwhile', 'genesis_prev_next_posts_nav' ); | |
// Change "Previous Page" and "Next Page" to "Newer Posts" and "Older Posts". | |
add_filter( 'genesis_prev_link_text', 'cc_prev_link_text' ); | |
add_filter( 'genesis_next_link_text', 'cc_next_link_text' ); | |
} | |
} | |
function cc_front_page_post_image() { | |
$img = genesis_get_image( array( | |
'format' => 'html', | |
'size' => 'medium', | |
'context' => 'archive', | |
'attr' => genesis_parse_attr( 'entry-image', array( | |
'alt' => get_the_title(), | |
) ), | |
) ); | |
if ( ! empty( $img ) ) { | |
printf( '<a href="%s" title="%s" class="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), esc_attr( 'aligncenter' ), $img ); | |
} | |
} | |
function cc_front_page_content_limit() { | |
the_content_limit( 250, 'Read More' ); | |
} | |
// Change "Previous Page" and "Next Page" to "Newer Posts" and "Older Posts". Only on front page. | |
function cc_prev_link_text( $prev_link_text ) { | |
return '« Newer posts'; | |
} | |
function cc_next_link_text( $next_link_text ) { | |
return 'Older posts »'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment