我想知道如何为帖子的图片分页。我有一个自定义的帖子类型设置,就像一个画廊-图像只。并希望为图像分页。我很难想出从哪里开始。
我在循环中使用get\\u posts()获取附加到帖子的图像。我想把它设置为每页显示30幅图像。
你知道我该从哪里开始吗?或者我需要改变在WP中设置此库功能的方式吗?
提前感谢!
我想知道如何为帖子的图片分页。我有一个自定义的帖子类型设置,就像一个画廊-图像只。并希望为图像分页。我很难想出从哪里开始。
我在循环中使用get\\u posts()获取附加到帖子的图像。我想把它设置为每页显示30幅图像。
你知道我该从哪里开始吗?或者我需要改变在WP中设置此库功能的方式吗?
提前感谢!
你可以使用paginate_links()
为整个库分页。这在很大程度上取决于您的永久链接设置。最好是检查一下other answers on that topic here on WPSE.
adjacent_post_link()
可以链接到下一篇或上一篇文章的功能-附件是“附件”类型的文章。它响应通过apply_filters( "{$adjacent}_post_link", $format, $link );
在哪里$adjacent
是previous
或next
.adjacent_post_link(
\'%link\' // format
,\'%date/%title\' // link
,false // in_same_cat
,\'\' // excluded_categories
,false // next/previous (previous = true)
);
the_title
附加了筛选器回调函数。如果您不想这样做,则需要删除它们:function wpse66660_attachment_remove_title_cbs( $title, $id )
{
is_attachment() AND remove_all_filters( current_filter() );
return $title;
}
add_filter( \'the_title\', \'wpse66660_attachment_remove_title_cbs\', 100, 2 );
如上所述,标签↑, 您可以使用三个“标签”:%link
, %date
和%title
.函数的输出如下:
\'<a href="\'.get_permalink($post).\'" rel="prev/next">\' . $link . \'</a>\'
现在%title
替换为帖子标题,并%date
替换为发布日期。这允许您向HTML锚定标记添加任何自定义值。这个%link
允许您将最终字符串中的所有内容(HTML锚定+链接+rel+值)替换为与永久链接设置一致的自定义内容。
使用后是否需要重置查询get_posts() ?我一直在看this page和我没有看到任何参考get_posts() ... 我不能肯定this 第页。我不明白为什么没有必要(尽管在我的测试页面上,它不会导致任何问题wp_reset_postsdata() `wp\\u reset\\u query()\'或“”rewind\\u posts()\'),但如果是,则应使用哪个函数。