duan111112 2016-05-29 16:26
浏览 39

PHP / Wordpress - 如何显示特定的小部件

I was searching and i found this: https://codex.wordpress.org/Function_Reference/the_widget

Based on this i have tried several things, one of them:

<?php the_widget( 'Phone'); ?>

It is a text widget, created in the sidebar. I was hoping with this code to get the content of widget i created with title Phone but however nothing is appearing. I can not display the content of the widget i created.

So my questions is, can you give an example how can i display the content of widget with widget title for example Phone ?

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • drlnsli18864734 2016-05-29 22:52
    关注

    The <?php the_widget( $widget, $instance, $args ); ?> function doesn't grab a widget you have defined in the WordPress admin. Instead it creates a new instance of a widget based on the class name of a registered widget.

    If for example you wanted to display WordPress's default text widget and have it display "Hello World" then you would use,

    the_widget( 'WP_Widget_Text', array( 'title' => 'Custom Widget Title', 'text' => 'Hello World!', 'filter' => true ) );

    If for example you use register_widget('Foo_Bar_Class'); to create a custom widget then you would use the following to display a custom instance of the widget outside of a sidebar.

    the_widget('Foo_Bar_Class', array( 'title' => 'My Foo Bar Widget', 'custom_widget_argument' => 'Some custom value.' );

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?