正常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' => "</divn", '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' => "</divn", 'before_title' => '<h2 class="widgettitle">', 'after_title' => "</h2>n", ); $instance = array( 'title' => 'Our Meta Widget', ); $mw->widget( $args, $instance ); }
免责声明 本站资源来自会员发布以及互联网收集,不代表本站立场,所有资源仅限学习及揭秘,请勿进行操作,请遵循相关法律法规,请在下载后24小时内删除.如有侵权争议、不妥之处请联系本站删除处理!请用户仔细辨认内容的真实性,避免上当受骗!