我想在wordpress之外的自定义php页面中获得一个特定的wordpress导航菜单作为列表。
如何做到这一点?
我想在wordpress之外的自定义php页面中获得一个特定的wordpress导航菜单作为列表。
如何做到这一点?
有几种方法,这里有一种:
// no theme output
define(\'WP_USE_THEMES\', false);
// initializes the entire Wordpress
require \'/path/to/your/wp/wp-blog-header.php\';
// here you print your menu
wp_nav_menu(\'your_theme_menu_location\');
即使主题输出被禁用,主题的功能也会被禁用。php仍应加载(并注册菜单位置)。您应该将HTML缓存在脚本中的某个位置,因为加载WP只是为了显示菜单可能会很慢。
具有以下功能:class my_walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { global $wp_query; $indent = ( $depth ) ? str_repeat(\"\\t\", $depth) : \'\';