dtcyv3985 2014-02-28 07:08
浏览 71

在wordpress仪表板页面部分创建小部件区域?

How to create a widget area in wordpress pages section. if I add below code in my functions.php file the widget created in dashboard menu section I want to add additional widget in my pages section not in dashboard.

Add a widget to the dashboard.

 //This function is hooked into the 'wp_dashboard_setup' action below.



function example_add_dashboard_widgets() {

wp_add_dashboard_widget(
             'example_dashboard_widget',         // Widget slug.
             'Example Dashboard Widget',         // Title.
             'example_dashboard_widget_function' // Display function.
    );  

}

add_action( 'wp_dashboard_setup', 'example_add_dashboard_widgets' );

Create the function to output the contents of our Dashboard Widget.

function example_dashboard_widget_function() {

// Display whatever it is you want to show.

echo "Hello World, I'm a great Dashboard Widget";
} 
  • 写回答

3条回答 默认 最新

  • dqa35710 2014-02-28 07:30
    关注

    you should register sidebar in functions.php as

    if (function_exists('register_sidebar')) {  
         register_sidebar(array(  
          'name' => 'widget_name',  
          'id'   => 'widget-id',  
          'description'   => 'Type something here',  
          'before_widget' => '<div id="one" class="two">',  
          'after_widget'  => '</div>',  
          'before_title'  => '<h2>',  
          'after_title'   => '</h2>'  
         ));  
        }
    

    it will register sidebar(widget) in your dashboard. Now you can you is it anywhere by

    <?php dynamic_sidebar('widget-id'); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线