首页 > 解决方案 > 在 10 秒内刷新 wordpress 网站中的 div 内容

问题描述

我正在使用 WordPress。我需要每 10 秒刷新一次 div。div 的内容是一个简码,其中包含来自数组的图像。

div 名称是 header_image 并且创建短代码的代码存在于 functions.php

所以添加了这段代码,没有任何效果

 <script src="http://code.jquery.com/jquery-latest.js"></script>

    <script>
        $(document).ready(function(){
            setInterval(function() {
                $(".header_image").load("functions.php");
            }, 1000);
        });

    </script>

div的内容

<div class="header_image">
    <a href="<?php echo $data[0]; ?>">
<img  src="<?php echo $data[1]; ?>">
</a>
</div>

标签: jquerywordpressrequire-onceadd-filter

解决方案


如果浏览器返回 404 Not found,你应该使用绝对路径而不是相对路径。

示例:如果您的 functions.php 文件位于 /wp-content/themes/theme-name/functions.php 中,则正确的代码应为:

$(".header_image").load("/wp-content/themes/theme-name/functions.php");

推荐阅读