Situation:
我正在开发我的第一个带有多个管理页面的Wordpress插件。该插件在管理菜单中有一个菜单和一些子菜单。我正在XAMPP、Windows 8.1 Pro上使用Wordpress 3.9。
Problem:
我想要实现的是添加新的按钮(链接),它位于所有帖子页面中。我的意思是,单击“所有帖子”页面中的“添加新帖子”链接时,它们会被带到“添加新帖子”页面本身,并选中子菜单“添加新帖子”。
这是我的代码:
function nes_general_settings_view () {
echo "In General Settings";
}
function nes_vendor_view () {
?>
All Vendors <a href="<?=HOW_TO_LINK_TO_nes_vendor_new_view_function?>">Add New Vendor</a>
<table>
...
</table>
<?php
}
function nes_vendor_new_view () {
echo "In New Vendor";
}
function nes_tell_us_view () {
echo "In Tell Us";
}
add_action("admin_menu", function () {
add_menu_page(
"Our Service",
"Our Service",
"manage_options",
"nes_general_settings",
"nes_general_settings_view",
null,
4
);
add_submenu_page( "nes_general_settings", "General Settings", "General Settings", 0, "nes_general_settings", "nes_general_settings_view");
add_submenu_page( "nes_general_settings", "Vendors", "Vendors", 0, "nes_vendor", "nes_vendor_view");
add_submenu_page( "nes_general_settings", "New Vendor", "New Vendor", 0, "nes_vendor_new", "nes_vendor_new_view");
add_submenu_page( "nes_general_settings", "Tell Us", "Tell Us!", 0, "nes_tell_us", "nes_tell_us_view");
});
Question:
如何生成此类链接(尤其是HOW_TO_LINK_TO_nes_vendor_new_view_function
在源代码中)?我应该使用特殊功能生成动态内容吗?另外,为了便于参考,你能告诉我哪个文件生成了所有帖子的管理页面吗?
最合适的回答,由SO网友:Douglas.Sesar 整理而成
如果我正确理解您的要求,您需要$menu_slug
添加菜单页时使用:
//add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
//add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
$your_link_url = admin_url( \'admin.php?page=\'.$menu_slug, \'http\' );
或者专门为你
$your_link_url = admin_url( \'admin.php?page=nes_vendor_new\', \'http\' );
您始终可以通过单击菜单项来验证链接,并查看它将带您去哪里。