无法重置查询以在第一次循环Wordpress之后显示ramdom帖子 [英] Can't reset query to show ramdom post after firs loop Wordpress
本文介绍了无法重置查询以在第一次循环Wordpress之后显示ramdom帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段代码在帖子下显示随机帖子。但是这段代码只显示了该帖子的作者写的帖子。什么是错的?
<! - post - >
<?php if(have_posts()):while(have_posts()):the_post(); ?>
<?php the_title(); ?>
<?php echo get_avatar(get_the_author_meta('ID'),32); ?>
<?php the_author(); ?>
<?php the_category(none); ?>
<?php the_date(); ?>
<?php the_content();?>
<?php $ key =video; echo get_post_meta($ post-> ID,$ key,true); ?>
<?php $ key =imagen; echo get_post_meta($ post-> ID,$ key,true); ?>
<?php endwhile; ?>
<?php else:?>
<?php endif; ?>
<! - ramdom post - >
<?php $ posts = $ posts = get_posts('orderby = rand& numberposts = 3'); foreach($ posts为$ post){?>
<?php the_post_thumbnail('photo-thumbnail')?>
<?php the_author(); ?>
<?php the_category(none); ?>
<?php}?>
解决方案
尝试添加< php wp_reset_query(); ?>
在第一个查询之后。
I have a piece of code to show a random post under a post. But this code only show me the post's write from the author of that post. Whats wrong?
<!-- post -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
<?php the_author(); ?>
<?php the_category(none); ?>
<?php the_date(); ?>
<?php the_content();?>
<?php $key="video"; echo get_post_meta($post->ID, $key, true); ?>
<?php $key="imagen"; echo get_post_meta($post->ID, $key, true); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<!-- ramdom post -->
<?php $posts = $posts = get_posts('orderby=rand&numberposts=3'); foreach($posts as $post) { ?>
<?php the_post_thumbnail('photo-thumbnail') ?>
<?php the_author(); ?>
<?php the_category(none); ?>
<?php } ?>
解决方案
Try adding <?php wp_reset_query(); ?>
after the first query.
这篇关于无法重置查询以在第一次循环Wordpress之后显示ramdom帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文