Skip to content

Instantly share code, notes, and snippets.

@cre8tivediva
Created August 9, 2014 19:54
Show Gist options
  • Save cre8tivediva/18cc4958e9dc0f3aa4e8 to your computer and use it in GitHub Desktop.
Save cre8tivediva/18cc4958e9dc0f3aa4e8 to your computer and use it in GitHub Desktop.
C8D Front Page Code
<?php
/**
* This file adds the Home Page to the Tidy Theme.
*/
add_action( 'genesis_meta', 'tidy_home_genesis_meta' );
/**
* Add widget support for homepage. If no widgets active, display the default loop.
*
*/
function tidy_home_genesis_meta() {
if ( is_active_sidebar( 'home-top' ) || is_active_sidebar( 'home-welcome' ) || is_active_sidebar( 'home-middle-left' ) || is_active_sidebar( 'home-middle-right' ) || is_active_sidebar( 'home-cta' ) || is_active_sidebar( 'home-bottom' ) ) {
// Force content-sidebar layout setting
add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' );
// Add tidy-home body class
add_filter( 'body_class', 'tidy_body_class' );
}
if ( is_active_sidebar( 'home-top' ) ) {
// Add excerpt length filter
add_action( 'genesis_before_loop', 'tidy_top_excerpt_length' );
// Add homepage widgets
add_action( 'genesis_before_loop', 'tidy_homepage_top_widgets' );
// Remove excerpt length filter
add_action( 'genesis_before_loop', 'tidy_remove_top_excerpt_length' );
}
if ( is_active_sidebar( 'home-middle-left' ) || is_active_sidebar( 'home-middle-right' ) || is_active_sidebar( 'home-cta' ) || is_active_sidebar( 'home-bottom' ) ) {
// Add homepage widgets
add_action( 'genesis_loop', 'tidy_homepage_widgets' );
}
}
function tidy_body_class( $classes ) {
$classes[] = 'tidy-home';
return $classes;
}
function tidy_excerpt_length( $length ) {
return 25; // pull first 50 words
}
function tidy_top_excerpt_length() {
add_filter( 'excerpt_length', 'tidy_excerpt_length' );
}
function tidy_remove_top_excerpt_length() {
remove_filter( 'excerpt_length', 'tidy_excerpt_length' );
}
function tidy_homepage_top_widgets() {
echo '<div class="home-feature">';
genesis_widget_area( 'home-top', array(
'before' => '<div class="home-top widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-welcome', array(
'before' => '<div class="home-welcome widget-area">',
'after' => '</div>',
) );
echo '</div>';
echo '<div style="clear:both;"></div>';
genesis_widget_area( 'home-cta-top', array(
'before' => '<div class="home-cta-top widget-area">',
'after' => '</div>',
) );
}
function tidy_homepage_widgets() {
if ( is_active_sidebar( 'home-middle-left' ) || is_active_sidebar( 'home-middle-right' ) ) {
echo '<div class="home-middle">';
genesis_widget_area( 'home-middle-left', array(
'before' => '<div class="home-middle-left widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-middle-right', array(
'before' => '<div class="home-middle-right widget-area">',
'after' => '</div>',
) );
echo '</div>';
}
genesis_widget_area( 'home-cta', array(
'before' => '<div class="home-cta widget-area">',
'after' => '</div>',
) );
genesis_widget_area( 'home-bottom', array(
'before' => '<div class="home-bottom widget-area">',
'after' => '</div>',
) );
}
genesis();
@cre8tivediva
Copy link
Author

The other theme I am using with the problem is Runway by Heather, version 1.9.

@cre8tivediva
Copy link
Author

But I am still confused here. If I used the widgetized area today. And a week from now say, "you know, I want this About page to be my home page. When I have turned the About page on as the Static home page - it was the About page. I didn't have to go to the Widget area and drag everything off of there. That's nuts. I still think something is wrong with this but you would know better than me. But to tell a client that if one day they want a static front page/home page they have to dismantle their entire home page widget area under widgets - well - there goes the framework - that's too much work!

@robincornett
Copy link

Well, if you just drag the widgets to inactive, it's pretty easy to swap them back and forth.

However, I think it is confusing if you want a site with a static front page, because why would you do that and then not use it? Which is why I took a different approach with a recent client, although they'd still have to remove some widgets, I suppose, if they went back to a recent posts setup.

I think part of the problem is that until recently, SP used home.php instead of front-page.php, and so a conditional to check if the front page was set as static or blog would probably not have worked at all, but I think you could change that, and not have to start from scratch.

@cre8tivediva
Copy link
Author

Brad Potter had me just change front-page.php to home.php and it works the way I want and the way the client wants it. Not sure why the functionality would be so drastically different between the two though. Thank you for taking time out to look at this for me. I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment