jQuery selectmenu wordpress

天涯浪子 提交于 2019-12-02 18:17:16

问题


I am moving a site from normal php to wordpress and currently they use jquery-selectmenu plugin for their select menus.

I have tried to enqueu the script in wordpress head with no luck.

The scripts from the previous site look as follows.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="<?php echo $siteurl; ?>css/custom-theme/jquery-ui-1.8.1.custom.css" type="text/css" /> 
<script type="text/javascript" src="<?php echo $siteurl; ?>js/select-menu.js"></script>
<script type="text/javascript" src="<?php echo $siteurl; ?>js/init.js"></script>

init.js simply calls the function and works

$(function(){
    $('select#speedC').selectmenu({style:'dropdown'});
});

Now in Wordpress i added the following to my head.

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/custom-theme/jquery-ui-1.8.1.custom.css" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

<?php wp_enqueue_script( 'jquery-ui-core' ); ?>
<?php wp_enqueue_script( 'swfobject' ); ?>
<?php wp_enqueue_script( 'ui-core-select', get_bloginfo('template_directory') . '/js/select-menu.js' ); ?>
<?php wp_enqueue_script( 'jquery-pajinate', get_bloginfo('template_directory') . '/js/jquery.pajinate.js' ); ?>
<?php wp_enqueue_script( 'jquery-ui', get_bloginfo('template_directory') . '/js/jquery-ui.1.7.2.min.js' ); ?>

And the script in my page

<script type="text/javascript">
    $j=jQuery.noConflict();

    // Use jQuery via $j(...)
    $j(document).ready(function(){
        $j('select#speedC').selectmenu({style:'dropdown'});
    });
</script>

Any ideas why it is not initiating?


回答1:


After doing some more research I found that the existing library is not currently kept up to date and not playing well with jQuery.

From now on refer to this one jQuery.ui.selectmenu.js




回答2:


I know this is an old question but adding this as it appears high up in Google and may help others.

Most of the jQuery UI components are included with WordPress but are not enqueued by default, you need to enqueue them with this.

    wp_enqueue_script( 'jquery-ui-selectmenu' );

There's a helpful list of the included components and the enqueue string at http://jafty.com/blog/tag/how-to-use-jquery-ui-in-wordpress/



来源:https://stackoverflow.com/questions/4245336/jquery-selectmenu-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!