代码之家  ›  专栏  ›  技术社区  ›  CrazyCoderMonkey

自动刷新WordPress Post Div

  •  0
  • CrazyCoderMonkey  · 技术社区  · 15 年前

    每次我用这个ID更新一篇文章时,我都会自动刷新一个ID为蓝色的DIV。 我知道jquery代码如下所示:

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

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

    2 回复  |  直到 14 年前
        1
  •  2
  •   ahmet2106    15 年前

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

    你可以创建一个javascript函数来加载WordPress创建的RSS文件的内容。( http://domain.tld/feed/rss/ )并将ID为XYZ的新文章的内容置于DIV蓝色中,使用 .html()

    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;

        2
  •  0
  •   CrazyCoderMonkey    15 年前

    实现这一点的方法是使用外部文件中的内容,这些内容可以在循环内使用,也可以在使用wp查询的循环外使用。希望这有帮助。