Developing Theme in Wordpress - Widgets do not appear

0

I'm trying to develop a theme from scratch in Wordpress by following video lessons. The problem did not just happen to me, there are people commenting on the same problem that is the fact that after all the PHP, HTML and CSS coding aimed at creating widgets, they just do not appear.

/*Na página index.php*/
<div class="right_sidebar"><?php get_sidebar(); ?></div>

/*Na página function.php*/
<?php
    if(function_exists('register_sidebar'))
        register_sidebar(array(
            'before_widget' => '<div class="widgets">',
            'after_widget' => '</div>',
            'before_title' => '<h2>',
            'after_title' => '</h2>',
        ));
?>

/*Na página style.css*/
.sidebar .widgets{
    width: 210px;
    background-color: #EEE;
    border: 1px solid #CCC;
    padding: 18px;
    font-size: 15px;
    color: #CCC;
    margin-top: 40px;
}

.sidebar .widgets h3{
    font-family: Helvetica;
    color: #333;
}

This code does not seem to work at all.

Thank you in advance.

    
asked by anonymous 02.12.2014 / 18:55

1 answer

1

The truth is that neither is that missing.

What is missing is the sidebar.php file "linked" with the sidebar you want to display. I usually use it like this:

<ul id="sidebar">
  <?php dynamic_sidebar( 'right-sidebar' ); ?>
</ul>

Remembering that the right-sidebar is the id (or name) of your sidebar. If you want to generate your own sidebar, I highly recommend the GenerateWP site.

Just paste the code into your functions.php:

// Register Sidebar
function custom_sidebar() {

    $args = array(
        'id'            => 'right-sidebar',
        'name'          => __( 'Sidebar Direita', 'text_domain' ),
    );
    register_sidebar( $args );

}

// Hook into the 'widgets_init' action
add_action( 'widgets_init', 'custom_sidebar' );
    
07.12.2014 / 03:32