WordPress、Jquery、wp_enqueue_script

发布于 2024-11-09 22:52:28 字数 787 浏览 0 评论 0原文

我需要帮助!

有人可以引导我从头到尾详细了解如何将 jquery 插件脚本添加到我的 WordPress 网站吗?

我是 Jquery 新手,上周我在网上搜索过。我自己尝试过几次,但就是不行。我在其他论坛上寻求帮助,但没有收到任何答复。这件事做起来相当简单吗?

只是为了让您知道,我需要一步一步的指示。只是当我在论坛上提出有关此问题的问题时,人们给我答案并假设我已经知道某些事情...我是 jquery 的初学者,我需要添加 jquery 脚本过程的每个步骤的帮助,从开始到结束。

我要添加的脚本在这里:

http://tympanus.net/codrops/2010/03/09/a-fresh-bottom-slide-out-menu-with-jquery/

我想将其添加到主题中的主页上我正在使用。

1)如何调用jquery(wp_enqueue_script) 2)我该把它放在哪里(上) 3) CSS - 我是否只需将脚本中的 css 附加到我的 style.css 文件中? 4)如何在wordpress页面上调用脚本进行操作? 5)如何合并html?

这些是我的一些问题。我一直在网上搜索,通常人们认为人们知道如何将 javascript 库合并到他们的主题中....我们中的一些初学者需要帮助:-)

感谢任何帮助!

谢谢!!!

~T

I am in need of help!

Can someone PLEASE walk me through the specifics, from start to finish, on how to add a jquery plugin script to my wordpress site?

I'm new to Jquery and I have searched the web for the last week. I've tried it myself several times and its just not working. I've asked for help on other forums and I haven't received any answers. Is this something fairly simple to do?

Just to let you know, I am in need step by step instructions. It's just that when I ask questions about this on forums, people are giving me answers and assuming that I already know certain things...I am a beginner with jquery and I need help with each step of the process of adding a jquery script, from start to finish.

The script I want to add is here:

http://tympanus.net/codrops/2010/03/09/a-fresh-bottom-slide-out-menu-with-jquery/

I want to add it on my homepage in the theme I'm using.

1) How do I call the jquery (wp_enqueue_script)
2) Where do I place this (above)
3) CSS - do I simply append the css from the script to my style.css file?
4) How do I call the script to action on the wordpress page?
5) How do I incorporate the html?

These are some of the questions that I have. I've been searching all over the net and usually people assume that people know how to incorporate javascript libraries into their themes....well some of us beginners need help :-)

Any assistance is appreciated!

Thanks!!!

~T

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲在坟头点根烟 2024-11-16 22:52:28

您链接到的滑出式菜单由图像、样式表、缩小版本的 jQuery 库和包含菜单 JavaScript 的 index.html 组成。

您下载的存档中包含的 jQuery 不是必需的,因为 jQuery 默认包含在 WordPress 中。如果您想将最新的缩小版 jQuery 添加到 WP,请从您的 functions.php 中的 google 库中执行此操作,如下所示:

function jq_load_from_google() {
    if (!is_admin()) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery',
            'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js');
        wp_enqueue_script( 'jquery' );
    }
}
add_action('init', 'jq_load_from_google');

您可以将 css 附加到现有样式表或(如以下示例所示)添加分别针对主题。将样式表重命名为 menu.css (或类似名称),将图像和样式表放入主题 /css 和 /images 文件夹中,并将以下内容添加到主题的 header.php 之前 wp_head() 并在主样式表之后:

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/menu.css" type="text/css" />

添加包含在下载的 index.html 中的 javascript(包含代码的第二个脚本,不是 jQuery 行)。 html 到您的主题的 header.php 之后 wp_head()

将js中所有出现的#menu更改为你的wordpress菜单的ul的ID。

The slide-out menu you linked to consists of images, a stylesheet, a minified version of the jQuery library and and index.html containing the javascript of the menu.

The jQuery included in the archive you downloaded is not neccessary, as jQuery is by default included in wordpress. If you want to add the newest minified jQuery to WP do it from the google libraries in your functions.php like so:

function jq_load_from_google() {
    if (!is_admin()) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery',
            'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js');
        wp_enqueue_script( 'jquery' );
    }
}
add_action('init', 'jq_load_from_google');

You could append the css to your existing stylesheet or (as in the following example) add it to the theme separately. Rename the stylesheet to menu.css (or the like), place the images and stylesheet in your themes /css and /images folders and add the following to your theme's header.php before wp_head() and after your main stylesheet:

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/menu.css" type="text/css" />

Add the javascript (the second script that contains code, not the jQuery line) included in the downloaded index.html to your theme's header.php after wp_head().

Change the all occurences #menu in the js to your wordpress menu's ul's ID.

幸福%小乖 2024-11-16 22:52:28

有关详细信息和示例,请参阅 WP 文档:http://codex.wordpress.org/Function_Reference/wp_enqueue_script

使用 Firebug 查找错误和冲突:http://getfirebug.com/

See the WP docs for details and examples: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Use Firebug to look for errors and conflicts: http://getfirebug.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文