正常WordPress只能在已注册的区域内使用显示小工具,下面的例子可以让小工具显示在任何地方。
在正文最后添加最近文章小工具
// 在正文最后添加最近文章小工具
add_filter( 'the_content', 'dcwd_append_recent_posts_widget_to_content' );
function dcwd_append_recent_posts_widget_to_content( $content ) {
$rpw = new WP_Widget_Recent_posts;
$args = array(
'before_widget' => '<div class="widget">',
'after_widget' => "</div\n",
'before_title' => '<h2 class="widgettitle">',
'after_title' => "</h2>\n",
);
$instance = array(
'title' => 'Some Recent Posts',
'number' => 2,
'show_date' => true,
);
ob_start();
$rpw->widget( $args, $instance );
$output = ob_get_contents();
ob_end_clean();
return $content . $output;
}
在wp_body_open钩子中调用 WordPress Meta 小工具
// 在侧边栏之外wp_body_open钩子中调用 WordPress Meta 小工具。
add_action( 'wp_body_open', 'dcwd_meta_widget_at_top' );
function dcwd_meta_widget_at_top() {
$mw = new WP_Widget_Meta;
$args = array(
//'before_widget' => '<li id="%1$s" class="widget %2$s">',
//'after_widget' => "</li>\n",
'before_widget' => '<div class="widget">',
'after_widget' => "</div\n",
'before_title' => '<h2 class="widgettitle">',
'after_title' => "</h2>\n",
);
$instance = array(
'title' => 'Our Meta Widget',
);
$mw->widget( $args, $instance );
}
© 版权声明
版权声明
1
本站名称:糖果博客
2
本站网址:wpocn.com
3
本网站的内容来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4
本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5
本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报。
6
本站附件资源、教程等内容如因时效原因失效或不可用,请评论区留言或联系站长及时更新。
THE END














暂无评论内容