例如,在循环中,我可以这样做吗
if lastpost {
}
else {
}
例如,在循环中,我可以这样做吗
if lastpost {
}
else {
}
if ($wp_query->current_post +1 == $wp_query->post_count) {
// this is the last post
}
如果创建了新的wp\\U查询对象,请将$wp\\U查询更改为您自己的查询变量。我给你编了一个简短的例子。应该解释如何在WP循环中获取第一个和最后一个帖子。
$post_count = 0;
$total = count($posts);
while (have_posts()) : the_post();
if ($post_count == 1 AND $post_count !== $total)
{
// This is the first post
}
if ($post_count == $total)
{
// This is the last item
}
$post_count++;
endwhile;
if (!get_next_post_link()) {
echo \'the last post here\';
}
if (!get_previous_post_link()) {
echo \'the last post here\';
}
OR
if (get_next_post_link()) {
echo \'the last post here\';
}
我正在为图书馆的收藏/档案室创建一个基本上静态的网站。由于我希望大多数内容只创建一次,并随着时间的推移慢慢添加或修改,而不是常规的帖子,所以我的第一个倾向是将所有内容都变成一个页面。另一方面,我有两个或三个类别的页面/帖子,我非常希望能够生成这些页面/帖子的列表,除了使用类别和帖子,我想不出一个好的方法来做到这一点。我知道有一个插件允许您使用类别标记页面,但我这样做时get\\u帖子并不总是有效。我有需要多个类别并相互重叠的内容,这一事实是否比这一内容基本上应该是静态的更重要?我有一个由专门针对特定主题的