我正在开发一个主题,我想调用可用的小部件,例如日历和安装的插件,我已经把它放在小部件面板的侧栏中,但在前端看不到。
侧栏。php代码->
<div id="sidebar">
<h2>News & Announcements</h2>
<ul class="sidebar_list">
<?php dynamic_sidebar(\'sidebar\'); ?>
You can color this theme as you wish, by its powerful theme options panel. It has great documentation.<br /><br /><br />
<?php if (is_page(array(\'home\', \'about-us\', \'academics\', \'admission\', \'activities\', \'hall-of-fame\', \'alumni\', \'photo-gallery\', \'news\' ))) ?>
<?php $menu=wp_nav_menu(\'menu=sidebar_menu\'); ?>
<?php if ( ! dynamic_sidebar( \'Sidebar\' )) : ?>
<?php //If dynamic sidebar not found show the default widgets ?>
<?php endif; ?>
</ul>
</div>
功能。php代码->
<?php
if(function_exists(\'register_sidebar\'))
{
// Sidebar Widget
register_sidebar(array(\'name\'=>\'Left-Sidebar\',
\'before_widget\'=>\'<li>\',
\'after_widget\'=>\'</li>\',
\'before_title\'=>\'<h3>\',
\'after_title\'=>\'</h3>\'
));
}
?>
最合适的回答,由SO网友:ucon89 整理而成
我将输入一个基本代码来创建新的小部件。在WordPress中调用register_sidebar;
在代码中,您没有输入ID。Id=>your-widget-id
将此代码放入函数中。php
function my_widget(){
register_sidebar( array(
\'name\' => __( \'Front Sidebar\', \'yourtheme\' ),
\'id\' => \'sidebar-1\',
\'description\' => __( \'This is description\', \'yourtheme\' ),
\'before_widget\' => \'<aside>\',
\'after_widget\' => \'</aside>\',
\'before_title\' => \'<h3>\',
\'after_title\' => \'</h3>\',
) );
}
add_action( \'widgets_init\', \'my_widget\' );
然后将此代码放入索引中。php或边栏。php(任意位置)
if ( is_active_sidebar( \'sidebar-1\' ) ) : //check the sidebar if used.
dynamic_sidebar( \'sidebar-1\' ); // show the sidebar.
endif;
记得把身份证放进去。
更多http://codex.wordpress.org/Function_Reference/register_sidebar