2017-04-26 22 views
2

插件功能我正在開發一個新的插件生成的數據到管理控制檯,我得到的數據庫值到我們的插件如何顯示這是由在WordPress

功能,但如何通過這些數據來查看file.I使用以下代碼插入

插件主文件。

<?php 
     /* 
      Plugin Name: All Attendees 
      Plugin URI: http://my-awesomeness-emporium.com 
      Description: a plugin to create awesomeness and spread joy 
      Version: 1.2 
      Author: Mr. Awesome 
      Author URI: http://mrtotallyawesome.com 
      License: GPL2 
     */ 
    ?> 



<?php 

    add_action('init', 'my_register_styles'); 
    function my_register_styles() { 
     add_action('admin_menu', 'all_attendees'); 
    } 
    function all_attendees(){ 

     $wpdb = EventPlus::getRegistry()->db->getDb(); 
     $sql = "SELECT id,reg_type,quantity,event_id,lname,fname,payment,payment_status,email FROM wp_evr_attendee ORDER BY id DESC Limit 30"; 
     $rows = $wpdb->get_results($sql); 
     echo "<pre>";print_r($rows);die; 
    } 

?> 
+0

有不同的方式,您可以將數據庫的輸出顯示到前端,如shortcode,hook。我建議你使用shorcode並在前端使用顯示數據/ HTML。 –

+0

@AshPatel如何讓$行進入視圖文件,我必須創建視圖文件請幫助它 –

回答

1

有顯示插件數據多方式, 一種方法是使用short code API

例如:

function call_back_function(){ 
    //function in plugin file with return value, 
    // custom fetch query 
} 

add_shortcode('shotcode', 'call_back_function'); 


echo do_shortcode('[shotcode]'); //for display 

可以顯示在表格格式數據相同的字印後/頁的傳統以及。

WP list table for word press admin

+0

#Ash patel我想顯示數據到管理面板 –

+0

你可以更新你想要顯示數據的位置你想要顯示數據的類型? –

+0

#Ash patel我更新了我的問題 –

2

如果你想顯示和儀表板創建模板頁面,在管理模板文件(主menu.php,子menu.php)你可以寫任何你想要的。

請仔細閱讀下面的代碼並將其粘貼到您的插件主文件中。

add_action('admin_menu', 'menu_page_name'); 

function menu_page_name() 
{ 
    // Add the top-level admin menu 


    $page_title = 'title'; 
    $menu_title = 'title'; 
    $capability = 'manage_options'; 
    $menu_slug = 'slug_name'; 
    $function = 'callback_main_menu'; 

    add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function); 

    // Add submenu page with same slug as parent to ensure no duplicates 

    add_submenu_page($menu_slug, 'Plugin Name', 'Plugin Name', $capability, 'pluginname', 'callback_sub_menu'); 

} 

function callback_main_menu() 
{ 
    if (!current_user_can('manage_options')) 
    { 
    wp_die('You do not have sufficient permissions to access this page.'); 
    } 
    else 
    { 
//include your admin template here 
    include('templates/main-menu.php'); 
    } 

    // Render the HTML for the Help page or include a file that does 
} 
function callback_sub_menu() 
{ 
    if (!current_user_can('manage_options')) 
    { 
    wp_die('You do not have sufficient permissions to access this page.'); 
    } 
    else 
    { 
//include your admin template here 
    include('templates/sub-menu.php'); 
    } 

    // Render the HTML for the Help page or include a file that does 
} 

如果你想顯示在前端數據或等,經過下面的代碼

function plugin_short_code(){ 
//Return your functionality here 
retrn $result; 

    } 

add_shortcode('plugin_shortcode', 'plugin_short_code'); 

您可以使用此簡碼在前端