好像WordPress 从2.2开始就自带了一个 Widget 的功能.用 Widget 可以自己定义侧边栏,也就是 sidebar ,好像 Widget 是一个插件作功能集成到Wordpress里面的。
有些主题不支持这个 Widget 其时只需修改functions.php、sidebar.php这两个文件就可以了。
在 functions.php里检查有没有以下代码,没有就加上,代码如下:
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
在 sidebar.php 里添加以下代码:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>
并把你定义边栏组件代码添加到 if 里面,完整代码如下:
<div id="sidebar">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<ul>
<h2><?php _e('最近评论'); ?></h2>
<ul><?php get_recent_comments($no_comments = 6); ?></ul>
</ul>
......
<?php endif; ?>
</div>
这样你用Widget 来添加后模块就不会追加到你自己定义的边栏上了,而是直接显示Widget 定义的模块。
除此以外你还可以不像被 Widget 定义的模块代码写在 这个 if 外面 。
PS:iKite 1.2 已经支持这个 Widget 了正在调试。发布的是1.0。
该文章以更新:
修正一个<li>标签错误。就是在<div id="sidebar">里模块的容器不要用<li>用<ul>,用<li>会错位,而且又不好控制。

2007.10.23 18:25 让你的WP主题支持Widget | 博客赚钱 says:
[…] 本文网址:https://xuui.net/wordpress/wordpress-theme-widget.html […]
2007.11.19 22:06 yoyo says:
非常好,学习了。
2008.01.25 21:27 Leeawan » Blog Archive » wordpress主题支持widget says:
[…] 文章来自xuhel’s blog 永久链接:http://leeawan.cn/?p=10 反向链接:http://leeawan.cn/wp-trackback.php?p=10 […]
2008.06.17 15:22 aishlai says:
真不错~~以后改模板就可以用到啦~~嘎嘎 学习学习
2009.06.17 13:51 bolo says:
博主的评论样式做的真好看啊