Wordpress 多循环条件冲突

发布于 2024-09-12 05:42:48 字数 208 浏览 2 评论 0原文

好吧,我有两个循环,在正文中和在侧边栏中。我还在页脚中有一个生成另一个循环的条件语句。我遇到的问题是在页脚中使用条件语句。由于侧边栏中的循环是最后调用的,因此 Wordpress 在页脚的条件语句中使用其变量,并导致其返回 false。

也许有某种方法可以使主体 $_GLOBAL 中的某些变量处于循环状态,这样我以后就可以使用它,并且不会与侧栏中的循环发生冲突?

谢谢

Alright I have two loops going, on in the body and on in the sidebar. I also have a conditional statement in the footer that generates another loop. The problem I'm running into is the use of the conditional statement in the footer. Because the loop in the sidebar was called last, Wordpress is using its variables in the conditional statement in the footer, and causing it to return false.

maybe there's some way to make some of the variables in loop in the body $_GLOBAL, that way I can use it later on and not have it conflict with the loop in the sidebar?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我心暖 2024-09-19 05:42:48

运行一个新的查询;您可以在标准 WP 循环中运行任意数量的代码。我不知道您在当前循环中正在做什么,但这是一个新查询的示例,它可以与主 WP 循环以及查询的其他实例共存:

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>

另请参阅 函数参考/WP 查询 « WordPress Codex函数参考/wp重置查询 « WordPress Codex

Run a new query; you can run as many as you want within the standard WP loop. I don't what you're doing in your current loops, but this is an example of a new query that can coexist with the main WP loop as well as other instances of the query:

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>

Also see Function Reference/WP Query « WordPress Codex and Function Reference/wp reset query « WordPress Codex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文