Php 向回显字符串添加查询

Php 向回显字符串添加查询,php,wordpress,Php,Wordpress,我有以下代码: <?php //display random sorted list of terms in a given taxonomy $counter = 0; $max = 5; //number of categories to display $taxonomy = 'category'; $terms = get_terms($taxonomy); shuffle ($terms); //echo 'shuffled'; if ($terms) { foreach($te

我有以下代码:

<?php
//display random sorted list of terms in a given taxonomy
$counter = 0;
$max = 5; //number of categories to display
$taxonomy = 'category';
$terms = get_terms($taxonomy);
shuffle ($terms);
//echo 'shuffled';
if ($terms) {
foreach($terms as $term) {
$counter++;
if ($counter <= $max) {
echo '<p><a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a></p> ';
  }
 }
}
?>

在echo内部,我想添加此代码,以便我们可以从该类别中提取最新的帖子

<?php while (have_posts()) : the_post(); ?>


我知道这是基本的PHP,但是我们如何添加它呢?

我有点不知所措,但是
有什么问题吗?_post()函数是什么?@CP510:用于迭代post索引。您需要设置一个新的WP_查询或以其他方式查询帖子。问题中的
while…
循环必须在实际查询之后。不能循环浏览未通过数据库查询生成的帖子。请看这里:一直向下滚动到“类别参数”啊,我错过了可湿性粉剂标签。没关系,我不使用它,所以我不知道。随机类别标题拉得很好,我只想它的最新文章标题和缩略图也出现。我能处理CSS