WordPress自带的Widget代码是写在/wp-includes/widgets.php中,在default-widgets.php中每个Widget写成了一个类。要修改Widget只要找到相应的类即可。
写在模板中的代码如下:
获取最新评论:
<?php wp_widget_recent_comments::widget(array("title" => "My Widget", 'before_title'=>'<h3>', 'after_title'=>'</h3>', 'before_widget'=>'<div>', 'after_widget'=>'</div>'), array("title" =>'Recent Comments', "number" => 5)); ?>
获取最新文章:
<?php wp_widget_recent_posts::widget(array("title" => "My Widget", 'before_title'=>'<h3>', 'after_title'=>'</h3>', 'before_widget'=>'<div>', 'after_widget'=>'</div>'), array("title" =>'Recent Comments', "number" => 5)); ?>
以下附上Wordpress自带的Widgets及其类名对应:
Widget名称
|
Widget类名
|
Widget介绍
|
页面 | WP_Widget_Pages | 您博客的 WordPress 页面 |
日历 | WP_Widget_Calendar | 您博客的文章日程表 |
文章索引模板 | WP_Widget_Archives | 您博客文章的月度存档 |
链接 | WP_Widget_Links | 您的链接表 |
功能 | WP_Widget_Meta | 登入/登出,管理,Feed 和 WordPress 链接 |
搜索 | WP_Widget_Search | 您博客的搜索框 |
文本 | WP_Widget_Text | 任意文本或HTML |
分类目录 | WP_Widget_Categories | 列表或是下拉菜单的分类目录 |
最近文章 | WP_Widget_Recent_Posts | 您博客的最近文章 |
最新评论 | WP_Widget_Recent_Comments | 最在侧边栏显示最新评论的列表 |
RSS | WP_Widget_RSS | 来自任何 RSS 或 Atom feed 的条目 |
标签云 | WP_Widget_Tag_Cloud | 您最常使用的标签云 |
Under Creative Commons License: Attribution Non-Commercial Share Alike
转载请注明出处:https://www.onexin.net/wordpress-widget-comes-with-the-latest-comments-in-the-template-call/