简体   繁体   中英

WordPress sidebar text widget

i'm using the Showcase Sidebar with a Text widget. I've inserting some HTML and Text and want that Text widget to display. What PHP code do I insert into the sidebar.php template to show the Text widget and any other ones that I add? Ideal I would like to only load the first Text Widget in from the Showcase Sidebar

would the code look something like this?

<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>

yes, it would look something like code you posted:

<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>

, but -

The code that you posted will only work if you have defined and registered such a sidebar (named : sidebar2 )

in your theme´s php you should have a register_sidebar() function call.

if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'=> 'Sidebar 2',
        'id' => 'sidebar2',
    ));
}

you can even customize it further with other parameters like .

    'before_widget' => '<li id="%1$s" class="widget %2$s">', 
    'after_widget' => '</li>',
    'before_title' => '<h2 class="offscreen">',
    'after_title' => '</h2>',

If your theme already have such a sidebar defined and registered , then the code you have posted will work and the front side will display all the widgets that you put to that sidebar (on the admin side) . If it is not defined by your theme you will need to define it or ADD it to the definitions of other sidebars .

Read more on the codex here and here about defining sidebars.

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