我想用手风琴菜单http://wordpress.org/plugins/jquery-vertical-accordion-menu/ 通过基于页面模板加载不同菜单的功能。
更重要的是,我希望将该元素划分为一个轴。下面是函数中的所有脚本。php:
function get_left_menu() {
if (is_page_template(\'page-akademia-biznesu.php\')) {
echo do_shortcode(\'[dcwp-jquery-accordion menu="Business menu" auto_close="true" event="click" save="true" disable="false" count="false" expand="false" disable_class="disabled"]\');
} elseif (is_page_template(\'page-forum-wiedzy-oze.php\')) {
echo do_shortcode(\'[dcwp-jquery-accordion menu="OZE menu" auto_close="true" event="click" save="true" disable="false" count="false" expand="false" disable_class="disabled"]\');
} elseif (is_page_template(\'page-o-nas.php\')) {
echo do_shortcode(\'[dcwp-jquery-accordion menu="About menu" auto_close="true" event="click" save="false" disable="false" count="false" expand="false" disable_class="disabled"]\');
} elseif (is_page_template(\'page-program-ambasadorski.php\')) {
echo do_shortcode(\'[dcwp-jquery-accordion menu="Ambassador menu" auto_close="true" event="click" save="true" disable="false" count="false" expand="false" disable_class="disabled"]\');
} elseif (is_page_template(\'page-program-edukacyjny.php\')) {
echo do_shortcode(\'[dcwp-jquery-accordion menu="Aside menu" auto_close="true" event="click" save="true" disable="false" count="false" expand="false" disable_class="disabled"]\');
}
die();
}
add_action("wp_ajax_nopriv_get_left_menu", "get_left_menu");
add_action("wp_ajax_get_left_menu", "get_left_menu");
function reload_menu_via_ajax()
{
wp_enqueue_script( \'function\', get_template_directory_uri().\'/library/js/menuReload.js\', \'jquery\', true);
wp_localize_script( \'function\', \'left_menu_reload\', array( \'ajaxurl\' => admin_url( \'admin-ajax.php\' ) ) );
}
add_action(\'template_redirect\', \'reload_menu_via_ajax\');
这里有jquery ajax脚本(menuReload.js):
jQuery(document).ready(function($) {
$(function() {
$(\'nav ul li\').click(function() {
$(\'#left-menu\').empty();
setTimeout(function() {
$.ajax({
method : "POST",
url : left_menu_reload.ajaxurl,
data : ( {
action : \'get_left_menu()\'
}),
success : function(data) {
$("#left-menu").html(data);
}
});
}, 2000);
});
});
});
我不太擅长ajax调用,所以如果这是显而易见的事情,请原谅我。但我最近真的很绝望,请帮帮我。