自动刷新Wordpress Post Div

时间:2010-01-24 05:21:30

标签: php jquery ajax wordpress html

我想每次更新带有该ID的帖子时,使用蓝色ID自动刷新某个div。 我知道Jquery代码看起来像这样:

var auto_refresh = setInterval(
function ()
{
$('#blue').load('load.php').fadeIn("slow");
}, 10000);

我只想重新加载div中的更新内容,而不是加载“load.php”,这是通过wordpress管理面板在外部完成的。任何帮助将不胜感激。谢谢大家!

2 个答案:

答案 0 :(得分:2)

这也是我的问题,一个想法:

您可以创建一个JavaScript函数,用于加载由WordPress(http://domain.tld/feed/rss/)创建的RSS文件的内容,并使用.html() <将新文章的内容与id xyz放在div蓝色中/ p>

function getContent(id) {
    // Here the Function which loads your RSS File and Match your Content of your Article with the_ID = id
}

var content = getContent(<?php the_ID(); ?>); // the_ID() is a WordPress function

function refresh(content) {
    $.get(content, function getNew(rssfile) {
        $("#blue").html('');
        $("#blue").html(rssfile);
    });
};

$(function(){
    refresh(content);
    var int = setInterval("refresh(content)", 10000);
});

我现在将搜索另一个想法,但这个例子只是一个想法,因为我还没有找到任何其他如何刷新id = id的div;

答案 1 :(得分:0)

执行此操作的方法是使用外部文件中的内容,该内容可以在循环中使用,也可以使用wp查询进行循环。希望这会有所帮助。

相关问题