gpt4 book ai didi

php - WordPress,循环内的外部查询

转载 作者:行者123 更新时间:2023-11-29 09:18:09 24 4
gpt4 key购买 nike

$qry = mysql_query("SELECT test1,test2 FROM ".$table." ORDER BY RAND() LIMIT 6"); 

$start = new WP_Query('showposts=6&orderby=rand');

if ($start->have_posts()) : while( $start->have_posts() && $rows = mysql_fetch_assoc($qry) ) : $start->the_post();

$test1 = $rows['test1'];

$test2 = $rows['test2'];

我可以像这样操纵wordpress循环......当我的表里面没有6个值时就会出现问题,有时会发生。然后,我的索引页不显示所有帖子。例如,如果表中有 3 个条目,则循环仅显示 3 个帖子,而不是 6 个。

如果我能让查询重复本身......以提供循环,那就太好了。

有什么想法吗?

最佳答案

$qry = mysql_query("SELECT test1,test2 FROM ".$table." ORDER BY RAND() LIMIT 6"); 

$start = new WP_Query('showposts=6&orderby=rand');

if ($start->have_posts()) : while( $start->have_posts() ) : $start->the_post();
$rows = mysql_fetch_assoc($qry)
if (!$rows) {
mysql_data_seek($qry,0);
$rows = mysql_fetch_assoc($qry);
}

关于php - WordPress,循环内的外部查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3389740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com