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)
Viewing 1 replies (of 1 total)
- The topic ‘Optimizing Code’ is closed to new replies.