使用Javascript的Wordpress根URL

时间:2013-02-27 19:49:53

标签: javascript wordpress url root

我在Wordpress网站上使用此脚本:JQuery Plugin: Random Image

我遇到的问题是我不知道在路径部分放入什么样的代码,以便Wordpress能够从images文件夹中获取图像。 / images还不够,因为它只会给我www.mydomain.com/images/image.jpg,显然这不是使用Wordpress时的整个URL。

我试过这个:wordpress path url in js script file

然而,我无法让它发挥作用。每当我放置

var templateUrl = '<?= get_bloginfo("template_url"); ?>';

在我的档案中,我刚收到错误

%3C?=%20get_bloginfo(%22template_url%22);%20?%3E/images/image.jpg

我做错了什么?

3 个答案:

答案 0 :(得分:0)

你必须回应它。

<?php echo get_bloginfo("template_url"); ?> 

或者您可以使用

<?php bloginfo("template_url"); ?>

答案 1 :(得分:0)

好的,我通过反复试验得到了它,我会在这里列出我做错的事情,以防其他人遇到同样的问题:

  1. 我将 var templateUrl 代码放在单独的javascript标记中。后来我把它移到了 $(文件)上面.ready(function(){

  2. 我将 templateUrl 放在实际的.js文件中。我后来把它移到: $('。shuffle')。randomImage({path:templateUrl + / images /});

  3. 最终结果如下:

    <script type="text/javascript">
    var templateUrl = '<?php bloginfo('template_directory'); ?>';
        $(document).ready(function() {
            $('.shuffle').randomImage({path: templateUrl + /images/});
        });
    </script>
    

    脚本现在完美运行!感谢大家的帮助! :)

答案 2 :(得分:0)

Network.URI