正常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 );
}
© 版权声明
NOTICE
2048074778@qq.com | Copyright © 2020~2026
01
DISCLAIMER
本站分享的WordPress主题/插件均遵循GPLv2 许可协议(开源软件),版权归原作者所有。如果有侵犯到您的权益,请与我们联系,将第一时间处理。
02
VIP PRIVILEGE
遇到付费内容?升级终身VIP即可全站免费畅享所有资源,自助开通会员或联系客服进行人工开通。
聊天 QQ 群:461848201
THE END









暂无评论内容