Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress ajax循环单击刷新_Ajax_Wordpress_Loops - Fatal编程技术网

Wordpress ajax循环单击刷新

Wordpress ajax循环单击刷新,ajax,wordpress,loops,Ajax,Wordpress,Loops,我在页面上显示一个随机的post循环。我想放一个“刷新”链接,通过ajax刷新循环的内容 这可能吗 这是我的循环: <ul id="content-inner" class="thumb-grid clearfix"> <?php query_posts('posts_per_page=20&orderby=rand'); ?> <?php if (have_posts()) : whi

我在页面上显示一个随机的post循环。我想放一个“刷新”链接,通过ajax刷新循环的内容

这可能吗

这是我的循环:

            <ul id="content-inner" class="thumb-grid clearfix">
            <?php query_posts('posts_per_page=20&orderby=rand'); ?>
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <li>
                    <a href="<?php the_permalink(); ?>">
                        <img src="<?php echo $my_image_url = get('thumbnail'); ?>" alt="" />
                        <span class="title"><?php the_title(); ?></span>
                        <span class="feat"><?php $articletags = strip_tags(get_the_tag_list('',', ',''));echo $articletags;?></span>
                    </a>
                </li>
            <?php endwhile;?>
            <?php endif; ?>
            <?php wp_reset_query(); ?>
            </ul>

谢谢

将随机邮政编码放在一个div中(如果您还没有),然后用JQuery刷新该div的内容

像这样的东西应该可以工作(但我还没有时间测试)

在页面引用JQuery的头部,然后使用JQuery。准备加载第一篇随机文章(用于初始页面加载):


/*…参考JQuery…*/
jQuery(文档).ready(函数($){
$(“#randomdiv”).html(“”);
});
....
[占位符文本]
$(函数(){
$(“#刷新”)。单击(函数(evt){
$(“#randomdiv”).html(“”);
evt.preventDefault();
})
})

因此,将整个循环代码放在一个名为getRandomPost()的函数(或其他什么)中,并将其放在wordpress“functions.php”文件中…,然后只需在页面头部调用“$(“#randomdiv”).html(“”””);进行初始加载,然后在页面主体中调用,如我在刷新时所示

您好,thxs-我附加了我使用的循环,我不确定我是否可以调整它,或者不能使用u发布的代码?请参阅上面我的更新答案,并让我知道这是否有效。谢谢谢谢你的帮助。当我点击刷新链接时,我似乎收到了错误“致命错误:调用未定义函数query_posts()”的回击。。。。有什么想法吗?Query_posts是一种WordPress方法,所以请确保我的脚本示例在WordPress初始化之后出现。。。很可能您正在编辑header.PHP。看起来不太像它。我尝试的每一件事都回击了上面的错误。
<head>

<script> /*...reference JQuery...*/ </script>
<script>
  jQuery(document).ready(function($) {
    $("#randomdiv").html("<?php getRandomPost() ?>");
  });
</script>

</head>

<body>
 ....

<div id="randomdiv">[placeholder text]</div>
<a id="refresh" href="#">click</a>

<!-- Then for the REFRESH:
make sure this script occurs AFTER your div (above) -->
<script> 
    $(function() {
      $("#refresh").click(function(evt) {
         $("#randomdiv").html("<?php getRandomPost() ?>");
         evt.preventDefault();
      })
    })
</script>

</body>