Skip to content

Instantly share code, notes, and snippets.

@cre8tivediva
Created August 9, 2014 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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();
@robincornett
Copy link

So, line 8 says that if no home page widgets are active, the loop will be removed. So whether or not the loop shows depends on whether you're using the home page widgets, and isn't influenced at all by whether you've set the front page to be static content or recent posts. That could be done, probably, but would be a different conditional. So if you want a static page for the home page, you need to remove content from every single home page widget area, or remove the remove_action( 'genesis_loop', 'genesis_do_loop' ); which you've already removed from here.

@cre8tivediva
Copy link
Author

But that didn't work like that before. I shouldn't have to dismantle the widget areas if say, I want a temporary static home page. That's crazy. And it didn't work like that before. If I wanted a static home, I just activated a page and it worked. Something is wrong here because it's not working on another client site either.

@robincornett
Copy link

I don't know why it's worked that way for you on other sites, because in all of the SP themes I've used, this has been pretty standard--either you have widgets, or you have static content/posts. You could try changing the conditionals to check if you're on a static home page v. a posts home page (http://codex.wordpress.org/Conditional_Tags#The_Front_Page), so your widgets would show up if you have Recent Posts selected, and your static page would show if you have Static Page selected, but the way most of the Genesis themes I've worked with have it set up like this, that if any home page widgets are active at all, then the posts or page content won't show. I agree that if you want to use a static page, it's totally not intuitive. I had to totally revamp the front-page.php for a client who didn't see why she would put content in the static page just for search engines, and then call it again somehow in a widget. I decided she was probably right, so I set up a front page that used the static content and has some optional widgets below, but even if they're populated, the loop is not removed. But I really haven't seen it done any other way with SP themes, theirs or third party, honestly.

@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