Adding Widgets to Sample Child Theme

Community Forums Forums General Discussion Adding Widgets to Sample Child Theme

This topic is: resolved

This topic contains 6 replies, has 3 voices, and was last updated by  jmweb 5 months, 4 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #102478

    jmweb
    Member
    Post count: 2

    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!

    #102490

    braddalton
    Participant
    Post count: 10222

    Depends 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


    #102591

    jmweb
    Member
    Post count: 2

    So, 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?

    #102594

    nunotmp
    Participant
    Post count: 164

    You 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 with add_action for example, if you want the widget to display just before the content you can use add_action( 'genesis_before_content', 'wpz_home_widget' );


    #102597

    braddalton
    Participant
    Post count: 10222

    @jmweb

    1. 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.


    #102602

    nunotmp
    Participant
    Post count: 164

    Because 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.


    #102604

    jmweb
    Member
    Post count: 2

    I’m fairly new to WordPress, however, I do know my way around PHP.

    Thanks for all your help guys!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.