Community Forums › Forums › Archived Forums › General Discussion › Adding Widgets to Sample Child Theme
Tagged: child theme, widgets
- This topic has 6 replies, 3 voices, and was last updated 9 years, 12 months ago by jmweb.
-
AuthorPosts
-
April 26, 2014 at 11:45 am #102478jmwebMember
Hi,
I just started using the Genesis Framework, and am fairly new with WordPress.
I am working on a site, and would like to create some widget areas on the home page of the Sample Child Theme. I've registered them, but I am unsure where I need to place the rest of the code in order for the widget areas to be displayed (template files, includes, etc)
Any help would be appreciated!
Thanks!
April 26, 2014 at 12:52 pm #102490Brad DaltonParticipantDepends on how many and it what position.
Th easiest solution is to pic a themes front page which already includes front page widgets and use that file.
Example
https://gist.github.com/braddalton/7fc263320d8da4185e68
April 27, 2014 at 9:13 am #102591jmwebMemberSo, if I am using the Sample Child Theme (which doesn't look like it has a front.php file) I could create one similar to the example code?
April 27, 2014 at 10:04 am #102594nunotmpMemberYou need to use font-page.php and to just clean up brad's code a bit here is how to register a single widget.
genesis_register_sidebar( array( 'id' => 'home-widget', 'name' => __( 'Home Widget', 'genesis' ), 'description' => __( 'This is a widget for the homepage.', 'genesis' ), ) );
After you register your widget area you can call it in the front-page.php or any theme template using this
function wpz_home_widget() { genesis_widget_area( 'home-widget', array( 'before' => '<div class="home-widget widget-area">', 'after' => '</div>', ) ); }
The wpz is just a prefix for WpZombies. You can change this to whatever you like.
Then you can hook this widget to where ever you would like withadd_action
for example, if you want the widget to display just before the content you can useadd_action( 'genesis_before_content', 'wpz_home_widget' );
April 27, 2014 at 10:15 am #102597Brad DaltonParticipant1. You simply create a new front-page.php file using a code editor like Notepad++ and copy the PHP from the view raw link in the Gist labelled front-page.php, paste it into the new file and save it, then upload the file to the root directory of your child theme.
2. The code in the Gist labelled functions.php goes in your child themes functions.php file.
@nunotmp The code comes directly from a child theme without any modification whatsoever so why does it need cleaning up?Please read the rules Don't: Post content to deliberately stir up controversy. No one likes a troll. Encourage trolls or unnecessary abuse of the forums.
April 27, 2014 at 10:26 am #102602nunotmpMemberBecause he claimed he is new to genesis and WordPress and throwing over 100 lines of code can be a bit overwhelming. In no way was my post meant to "stir up controversy". Sometimes copy and pasting code is not the best solution for a problem. I attempted to break down the section of code to help him better understand what was going on.
April 27, 2014 at 10:28 am #102604jmwebMemberI'm fairly new to WordPress, however, I do know my way around PHP.
Thanks for all your help guys!
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.