简体   繁体   中英

Appy Wordpress Widget to Widget area

I'm working the first time with WordPress, now I'm trying to add a custom Widget to an HTML box.

The HTML: The blank News box

I started to read a bit about widgets and the tutorials told me to create a new Widget area inside my functions.php document, which i did with the following code:

<?php
/**
 * Register our sidebars and widgetized areas.
 *
 */
function arphabet_widgets_init() {

    register_sidebar( array(
        'name'          => 'Home right sidebar',
        'id'            => 'home_right_1',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'arphabet_widgets_init' );
?>

Now i went into my index.php document, which stores the HTML so I tried to add the following code to the HTML blank news box:

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>

After i finished this also, i went into my WordPress admin menu and applied the plugin to the widget.

But it wouldn't show up...

Does anyone have a idea why?

update your index.php code as below:

<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
    <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
        <?php dynamic_sidebar( 'home_right_1' ); ?>
    </div><!-- #primary-sidebar -->
<?php endif; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM