php - 如何在 WordPress 中使用 jQuery Cycle 插件?

标签 php javascript jquery wordpress jquery-plugins

我已经尝试了所有我能想到的方法。这不应该这么难。有人可以向我解释一下在 WordPress 中使用 jQuery 的过程吗(特别是 jQuery Cycle 插件)?

在 header.php 中我有:

<?php
    wp_enqueue_script('jquery.cycle.all.min', '/wp-content/themes/andrewhavens/jquery.cycle.all.min.js', array('jquery'));
    wp_enqueue_script('featured-work-slideshow', '/wp-content/themes/andrewhavens/featured-work-slideshow.js');
    wp_head();
?>

我已将这两个js文件上传到我的主题目录中。

在featured-work-slideshow.js 中我有:

jQuery(document).ready(function($) {
    $('#featured-works').cycle('fade');
});

在我的模板中,我有:

<div id="featured-works">
    <?php query_posts('category_name=featured-work&showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="featured-work">
            <div class="featured-work-image-container" style="float:left; width:600px;">
                <?php $image = get_post_meta($post->ID, 'homepage-image', true); ?>
                <img src="<?php echo $image; ?>" width="500" height="300" style="margin-left:30px;">
            </div>
            <p style="float:left; width:300px;">
                <?php the_title(); ?><br />
                <a href="<?php the_permalink() ?>">Read More!</a>
            </p>
        </div>
    <?php endwhile;?>
</div>

我做错了什么???

最佳答案

我已经弄清楚了。我不小心忘记指定正确的路径:

<?php
    wp_enqueue_script('jquery.cycle.all.min', '/wp-content/themes/andrewhavens/jquery.cycle.all.min.js', array('jquery'));
    wp_enqueue_script('featured-work-slideshow', '/wp-content/themes/andrewhavens/featured-work-slideshow.js');
    wp_head();
?>

应该是

<?php
   wp_enqueue_script('jquery.cycle.all.min', '/wp-content/themes/andrewhavens/js/jquery.cycle.all.min.js', array('jquery'));
   wp_enqueue_script('featured-work-slideshow', '/wp-content/themes/andrewhavens/js/featured-work-slideshow.js');
   wp_head();
?>

否则,它工作得很好

关于php - 如何在 WordPress 中使用 jQuery Cycle 插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/925985/

相关文章:

php ImageMagick gif 调整大小保持动画

javascript - 使用承载授权将 PouchDB 同步到 Cloudant 时出现错误

jquery - 响应式网站 - 幻像宽度导致水平滚动条

javascript - 如何使用 JavaScript/HTML5 创建 .txt 文件?

jquery - TextBox 的启用禁用动态使用 knockout 观察?

javascript - Uncaught Error : Not enough space for Photobooth. 最小高度/宽度为 200 像素

php - 在 .htaccess 文件中操作 PHP 响应的 header ?

PHP 使用 DateTime 的每月第一天

php - 获取远程数据 - PHP 还是 JavaScript?

javascript - Cypress :特定应该命令中的自定义超时