我是一名Java程序员,但也了解PHP。现在我正在努力提高我在PHP和Wordpress方面的技能。我最近创建了一个wordpress主题,现在我正试图注册我的侧边栏,使其成为小工具。我正在学习一些教程(注册侧边栏(,但我似乎不清楚在我的情况下该如何做。我只是不知道我会在下面的东西上涂什么。
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
?>
这是我当前的侧边栏
<div id="primary-sidebar">
<a href="?"><img src="<?php bloginfo('template_directory'); ?>/images/logo.jpg" alt="Company Logo" class="logo" /></a>
<ul class="menu">
<li><a href="?" <?php echo ($page == NULL) ? 'class="active"': '';?>>Home</a></li>
<li><a href="?page=philosophy" <?php echo ($page == 'philosophy') ? 'class="active"': '';?>>Philosophy</a></li>
<li><a href="?page=investments" <?php echo ($page == 'investments') ? 'class="active"': '';?>>Investments</a></li>
<li>
<a href="?page=about" <?php echo ($page == 'about') ? '': '';?>>About Us</a>
<ul>
<li><a href="?page=team" <?php echo ($page == 'team') ? 'class="active"': '';?>>Our Team</a></li>
<li><a href="?page=company" <?php echo ($page == 'company') ? '': '';?>>Company Profile</a></li>
</ul>
</li>
<li><a href="?page=contact" <?php echo ($page == 'contact') ? 'class="active"': '';?>>Contact Us</a></li>
</ul> <!-- END OF MENU -->
</div> <!-- END OF PRIMARY SIDEBAR -->
伙计们,你能帮我吗?如有任何帮助和意见/建议,我们将不胜感激。非常感谢。
创建一个functions.php
文件(如果您还没有这样做(并添加以下代码:
<?php
function register_sidebar() {
register_sidebar(array(
'name' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
}
add_action('init', 'register_sidebar');
?>
function register_sidebar() {
register_sidebar(array(
'name' => '', //this is the widgets name , it shows up in admin
'id' => '', // this is widget ID, must have to actually call it
'description' => '', // under name in admin, not needed
'before_widget' => '', // HTML placed before ( usually a div)
'after_widget' => '', // HTML placed after ( usually a div)
'before_title' => '', // HTML placed before title( usually a div)
'after_title' => '', // HTML placed before after ( usually a div)
));
}
add_action('init', 'register_sidebar');
要调用您编写的侧边栏,请使用<?php dynamic_sidebar( 'id' ); ?>
我认为唯一需要的参数是ID和注册时的名称。