I am writing a plugin, that will list a number of entries from a custom set of tables. I added the main page for the plugin using the following WordPress functions:
// Add menu and pages to WordPress admin area
add_action('admin_menu', 'myplugin_create_top_level_menu');
function myplugin_create_top_level_menu() {
add_menu_page('MyPlugin', 'MyPlugin', 'manage_options', 'myplugin-top-level-admin-menu');
add_submenu_page('myplugin-top-level-admin-menu', 'MyPlugin Admin Page', 'Admin Page', 'manage_options', 'myplugin-top-level-admin-menu', 'myplugin_admin_page');
}
function myplugin_admin_page {
// Code to display the admin page for my plugin (both php and html code)
// This includes the following seudo code (in php)
foreach ($results_from_db as $result) {
// CODE TO DISPLAY RESULTS IN AN HTML TABLE *** I NEED HELP HERE ***
}
}
Now, if you read the above code closely, you note that there is a comment that states ‘I NEED HELP HERE’; here are more details:
I know how to display everything on the the admin page that I created. The admin page will read from the custom tables, and display results as HTML table rows.
I only need to link each row to a page, lets call it ‘Entry Details Page’. The idea is, for each row in the HTML table, there will be a link, and when I click on that link, it will take me to another page that displays more details about that row.
I was thinking of using add_submenu_page as described here, but honestly I did not understand how to use it and how to include it in my code. I tried something like this but I think it is wrong:
function myplugin_admin_page {
// Code to display the admin page for my plugin (both php and html code)
// This includes the following seudo code (in php)
foreach ($results_from_db as $result) {
// CODE TO DISPLAY RESULTS IN AN HTML TABLE *** I NEED HELP HERE ***
// The following line of code is incorrect, but to show you the idea
echo '<a href="' . add_submenu_page(NULL,'Entry Details Page','Entry Details Page','manage_options','details-page', 'myplugin_details_page'); . '">View</a>';
}
}
myplugin_details_page () {
// Code to display the details page
}
Now, the two problems I am facing are:
- How to add the details page correctly (it is clear that what I am doing above in the second code snippet is incorrect)?
- How to include params in the details page (I need to pass a row id to view the details)?
I think I am really close to solving the problem, however I could not find enough documentation to finish it, so please help, and I really really thank you.
Cheers.
I am less convinced that I know what you are doing than I once was.
You are using two additional Core functions in there, so for reference:
It’s better to add another parameter in URL and call it “action” and based on action render a different template for different action.