【问题标题】:Auto Refresh Wordpress Post Div自动刷新 Wordpress Post Div
【发布时间】:2011-01-08 17:22:19
【问题描述】:

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

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

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

【问题讨论】:

    标签: php jquery ajax wordpress html


    【解决方案1】:

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

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

    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;

    【讨论】:

    • 谢谢伙计,我找到了使用 wp 查询和内容的解决方案。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-02
      • 2011-03-06
      • 1970-01-01
      • 2012-12-15
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多