在 10 秒内刷新 wordpress 网站中的 div 内容
refreshing a div content in 10 sec in wordpress website
我正在使用 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>
如果浏览器return 404 Not found,你应该使用绝对路径而不是相对路径。
示例:如果您的 functions.php 文件在 /wp-content/themes/theme-name/functions.php 中,正确的代码应该是:
$(".header_image").load("/wp-content/themes/theme-name/functions.php");
这解决了 issue.Added JS 函数并使用 setinterval 每 10 秒更改图像
<script>
var $image_square = <?php echo json_encode($image_array_square); ?>;
var $link_square =<?php echo json_encode($link_array_square); ?>;
var i = 0;
var renew = setInterval(function(){
if(links.length == i){
i = 0;
}
else {
document.getElementById("squareImage").src = $image_square[i];
document.getElementById("squareLink").href = $link_square[i];
i++;
}
},10000);
</script>
//To display the first image in the website,taking the 2nd image from array/
<div class="square_image">
<a id="squareLink" href="<?php echo $link_array_square[2]; ?>" onclick="void window.open(this.href); return false;">
<img id="squareImage" src="<?php echo $image_array_square[2]; ?>" >
</a>
</div>
</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>
如果浏览器return 404 Not found,你应该使用绝对路径而不是相对路径。
示例:如果您的 functions.php 文件在 /wp-content/themes/theme-name/functions.php 中,正确的代码应该是:
$(".header_image").load("/wp-content/themes/theme-name/functions.php");
这解决了 issue.Added JS 函数并使用 setinterval 每 10 秒更改图像
<script>
var $image_square = <?php echo json_encode($image_array_square); ?>;
var $link_square =<?php echo json_encode($link_array_square); ?>;
var i = 0;
var renew = setInterval(function(){
if(links.length == i){
i = 0;
}
else {
document.getElementById("squareImage").src = $image_square[i];
document.getElementById("squareLink").href = $link_square[i];
i++;
}
},10000);
</script>
//To display the first image in the website,taking the 2nd image from array/
<div class="square_image">
<a id="squareLink" href="<?php echo $link_array_square[2]; ?>" onclick="void window.open(this.href); return false;">
<img id="squareImage" src="<?php echo $image_array_square[2]; ?>" >
</a>
</div>
</div>