如何在 WordPress 循环中显示任意数量的帖子

WordPress 使用Loop来显示您的每个帖子。使用 The Loop,WordPress 处理要显示在当前页面上的每个帖子,并根据它们如何匹配 The Loop 标签中的指定标准来格式化它们。通常,要显示的帖子数量是在阅读选项卡下的 WordPress 管理面板设置区域中设置的。但在本文中,我们将向您展示如何使用超级循环来覆盖该数字,这将允许您在该特定 WordPress 循环中显示任意数量的帖子。这将允许您自定义页面的显示,包括作者简介、侧边栏等。

打开一个您想要放置帖子的模板文件,然后简单地添加这个循环:

// if everything is in place and ready, let’s start the loop   // to display ‘n’ number of posts, we need to execute the loop ‘n’ number of times// so we define a numerical variable called ‘$count’ and set its value to zero// with each iteration of the loop, the value of ‘$count’ will increase by one// after the value of ‘$count’ reaches the specified number, the loop will stop// *USER: change the ‘n’ to the number of posts that you would like to display  // for CSS styling and layout purposes, we wrap the post content in a div// we then display the entire post content via the ‘the_content()’ function// *USER: change to ‘‘ to display post excerpts instead 

 // here, we continue with the limiting of the number of displayed posts// each iteration of the loop increases the value of ‘$count’ by one// the final two lines complete the loop and close the if statement 

你完成了。在设计作者的模板时,此代码对您特别有帮助,因为您希望控制每个循环中显示的帖子数量。

资料来源:WordPress 的超级循环