Skip to content

Instantly share code, notes, and snippets.

@surefirewebserv
Last active April 16, 2019 14:22
Show Gist options
  • Save surefirewebserv/3860625 to your computer and use it in GitHub Desktop.
Save surefirewebserv/3860625 to your computer and use it in GitHub Desktop.
Simple Homepage Layout for Genesis Framework.
<?php
add_action( 'genesis_after_header', 'sf_featured_slideshow' );
/**
* Add slide show widget area after the header.
*
* @author Sure Fire Web Services
* @link http://surefirewebservices.com/?p=1542
*
* @return Return null if not the homepage post.
*/
function sf_featured_slideshow() {
if ( ! is_home() || ! is_front_page() )
return;
genesis_widget_area( 'home-featured-slideshow', array(
'before' => '<div id="home-featured-slider" class="widget-area">',
) );
}
add_action('get_header', 'sf_remove_loop');
/**
* Remove Loop on Home Page Only
*
* @author Sure Fire Web Services
* @link http://surefirewebservices.com/?p=1542
*
*/
function sf_remove_loop() {
if ( ! is_home() || ! is_front_page() )
return;
remove_action( 'genesis_loop', 'genesis_do_loop' );
}
/** Remove Standard Loop */
add_action( 'genesis_loop', 'sf_do_featured_boxes' );
/**
* Add 3 featured boxes to the homepage.
*
* @author Sure Fire Web Services
* @link http://surefirewebservices.com/?p=1542
*
* @return Return null if not the homepage post.
*/
function sf_do_featured_boxes() {
if ( ! is_home() || ! is_front_page() )
return;
remove_action( 'genesis_loop', 'genesis_do_loop' );
echo '<div class="wrap">';
genesis_widget_area( 'home-featured-1', array(
'before' => '<div id="home-featured-1" class="widget-area one-third first">',
) );
genesis_widget_area( 'home-featured-2', array(
'before' => '<div id="home-featured-2" class="widget-area one-third">',
) );
genesis_widget_area( 'home-featured-3', array(
'before' => '<div id="home-featured-3" class="widget-area one-third">',
) );
echo '</div>';
}
/**
* Register Home Page Widget Areas.
*
* @author Sure Fire Web Services
* @link http://surefirewebservices.com/?p=1542
*
*/
genesis_register_sidebar(
array(
'id' => 'home-featured-slideshow',
'name' => __( 'Feature Slideshow Area', 'themename' ),
'description' => __( 'This is the featured slide show area under the header.', 'themename' ),
) );
genesis_register_sidebar(
array(
'id' => 'home-featured-1',
'name' => __( 'Home Featured Left', 'themename' ),
'description' => __( 'This is the featured left area on the homepage.', 'themename' ),
) );
genesis_register_sidebar(
array(
'id' => 'home-featured-2',
'name' => __( 'Home Featured Middle', 'themename' ),
'description' => __( 'This is the featured middle area on the homepage.', 'themename' ),
) );
genesis_register_sidebar(
array(
'id' => 'home-featured-3',
'name' => __( 'Home Featured Right', 'themename' ),
'description' => __( 'This is the featured right area on the homepage.', 'themename' ),
) );
@GaryJones
Copy link

Commenting here for convenience.

  • Home page is two words, not homepage (article).
  • It's "WordPress", not "Wordpress" or "wordpress" (article).
  • Watch out for code standards after commas (e.g. between parameters) - you're often missing a space. e.g. should be foo, bar not foo,bar.
  • { and } on line 13 and 15 optional, as conditional action is only a single line.
  • Lines 17, 39-40 are quite long - don't be afraid to put the arguments on multiple lines - makes it easier to read, and re-arrange as the code develops.
  • Include a trailing comma after the last item in an array, even if it's only one item. Makes adding extra items easier, and easier to re-order items.
  • When replacing a genesis_do_* function, keep the do part in your new function name.
  • Line 38 and 42 - keep PHP strings as single quotes, and HTML as double-quotes.
  • As noted in the article, since this is a tutorial for Genesis, re-use existing classes where possible - don't even bother suggesting fourcol as a class name (it also goes against the WP standard of splitting words in class names with hyphens).
  • You've correctly prefixed your functions, but you've not prefixed the sidebar IDs.
  • Keep => in multi-line arrays lined up with spaces, not tabs. Makes it easier to read values.
  • Be careful about adding "left" and "right" to widget names - someone could style the divs to float in some other order, particularly in a RTL-language site.
  • Description on line 62 is wrong.
  • When doing multi-line function calls, keep the first argument on the next line after the opening ( i.e. array( from line 47 should be on line 48, indented as 'id' currently is, and everything else moved down a line:
genesis_register_sidebar(
    array(
        'id'          => 'home-featured-1',
        'name'        => __( 'Home Featured Left', 'themename' ),
        'description' => __( 'This is the featured left area on the home page.', 'themename' ),
    )
);

@wpsmith
Copy link

wpsmith commented Oct 9, 2012

sf_featured_slideshow & sf_featured_boxes should have ()

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