Title: Optimizing Code
Last modified: August 20, 2016

---

# Optimizing Code

 *  [digisavvy](https://wordpress.org/support/users/digisavvy/)
 * (@digisavvy)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/optimizing-code/)
 * I’m creating a custom child theme w/ Genesis. The home page is going to be static.
   I’ve created a home page template and the necessary widget areas in the child’s
   functions.php file.
 * I’ve created the following widget areas in functions.php
 *     ```
       // Widget Areas
       	genesis_register_sidebar( array(
       	    'id'            => 'home-feature',
       	    'name'          => __( 'Home Feature Article', 'NRG' ),
       	    'description'   => __( 'This is a widget area for your home page featured article area', 'NRG' ),
       	) );
       	genesis_register_sidebar( array(
       	    'id'            => 'home-left-feature',
       	    'name'          => __( 'Home Feature Left', 'NRG' ),
       	    'description'   => __( 'This is a widget area for your home page featured article area', 'NRG' ),
       	) );
       	genesis_register_sidebar( array(
       	    'id'            => 'home-right-feature',
       	    'name'          => __( 'Home Feature Right', 'NRG' ),
       	    'description'   => __( 'This is a widget area for your home page featured article area', 'NRG' ),
       	) );
       	genesis_register_sidebar( array(
       	    'id'            => 'home-bottom-feature',
       	    'name'          => __( 'Home Feature Bottom', 'NRG' ),
       	    'description'   => __( 'This is a widget area for your home page featured article area', 'NRG' ),
       	) );
       ```
   
 * For the home page template, here’s what I have:
 *     ```
       <?php
       /**
        * WARNING: This file is part of the core Genesis framework. DO NOT edit
        * this file under any circumstances. Please do all modifications
        * in the form of a child theme.
        *
        * Template Name: Home Page Template
        */?>
       <?php get_header(); ?>
   
       <?php genesis_before_content_sidebar_wrap(); ?>
       <div id="content-sidebar-wrap">
   
       	<?php genesis_before_content(); ?>
       	<div id="content" class="hfeed">
   
       		<?php if (!dynamic_sidebar('home-feature')) : ?>
   
       		<?php endif; ?>
       	</div><!-- end #content -->
       	<?php genesis_after_content(); ?>
   
       </div><!-- end #content-sidebar-wrap -->
       <?php genesis_after_content_sidebar_wrap(); ?>
   
       <?php get_footer(); ?>
       ```
   
 * What I’m not clear on is this syntax to make my code for this template more “
   efficient.” I want to include 4 widget areas on the home page template. And I’ve
   modified the above code with the following and it works. I just want to know 
   a better way to write this, because four consecutive if statements seems inefficient.
 *     ```
       <?php genesis_before_content(); ?>
       	<div id="content" class="hfeed">
   
       		<?php if (!dynamic_sidebar('home-feature')) : ?>
       		<?php endif; ?>
       		<?php if (!dynamic_sidebar('home-left-feature')) : ?>
       		<?php endif; ?>
       		<?php if (!dynamic_sidebar('home-right-feature')) : ?>
       		<?php endif; ?>
       		<?php if (!dynamic_sidebar('home-bottom-feature')) : ?>
       		<?php endif; ?>
       	</div><!-- end #content -->
       	<?php genesis_after_content(); ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [digisavvy](https://wordpress.org/support/users/digisavvy/)
 * (@digisavvy)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/optimizing-code/#post-2766820)
 * So one of my buddies helped me out here and gave me some tips. Since this is 
   genesis the structural parts I was calling weren’t needed and could be replaced
   w/ genesis();
 * Here’s what I ended up with:
 *     ```
       <?php
       /**
        * Template Name: Alt Home Page
        * Description: A Three Column Layout for the Home Page
        */
   
       // Force full width layout
       add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content_sidebar' );
   
       // Build our custom loop
       remove_action( 'genesis_loop', 'genesis_do_loop' );
       add_action( 'genesis_loop', 'special_loop' );
       function special_loop() {
       ?>
   
       	 	<div class="featured-article"><?php if (!dynamic_sidebar('home-feature')) : ?>
       		<?php endif; ?></div>
       		<div class="featured-left"><?php if (!dynamic_sidebar('home-left-feature')) : ?>
       		<?php endif; ?></div>
       		<div class="featured-right"><?php if (!dynamic_sidebar('home-right-feature')) : ?>
       		<?php endif; ?></div>
       		<div class="featured-bottom"><?php if (!dynamic_sidebar('home-bottom-feature')) : ?>
       		<?php endif; ?></div>
   
       <?php
       }
       genesis();
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Optimizing Code’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [page templates](https://wordpress.org/support/topic-tag/page-templates/)

 * 1 reply
 * 1 participant
 * Last reply from: [digisavvy](https://wordpress.org/support/users/digisavvy/)
 * Last activity: [13 years, 12 months ago](https://wordpress.org/support/topic/optimizing-code/#post-2766820)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
