Auto Refresh Wordpress Post Div

坚强是说给别人听的谎言 提交于 2019-12-13 03:04:04

问题


I would like to autorefresh a certain div with the ID of blue everytime I update a post with that ID. I know the Jquery code looks something like this:

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

Instead of loading "load.php" I would just like to reload the updated contents in the div which is done externally through the wordpress admin panel. Any help would be greatly appreciated. Thanks everyone!


回答1:


This was my Problem too, an idea:

You can create a JavaScript function which loads the content of your RSS file created by WordPress (http://domain.tld/feed/rss/) and puts the content of the new article with the id xyz in the div blue using .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);
});

I will search now for an other Idea, but this example is just an idea, because i haven't find anything else how to refresh just an div with id = id;




回答2:


The way to do this is by using the content in the external file which can be used within the loop or with out the loop using wp query. Hope this helps.



来源:https://stackoverflow.com/questions/2126065/auto-refresh-wordpress-post-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!