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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条