根据段落数自动在数据库中创建新页面

发布于 2024-12-29 14:22:52 字数 439 浏览 3 评论 0原文

我正在创建一个帖子,但它包含很多段落,我希望每个帖子不超过 5 个段落。也就是说,如果我的帖子有 15 段,将自动分为 3 个帖子。

例如:我创建了标题为“我的第一篇文章”的帖子,他有 15 段。当发送到数据库时,它将被分为第 5 段的三个帖子,具有不同的 url (site.com/my-first-post/page-1 - site.com/my-first-post/page-2 - site.com/my-first-post/page-1 - site.com/my-first-post/page-2 - site.com/my-first-post/page-1 - site.com/my-first-post/page-2 com/my-first-post/page-3)并具有相同的标题或加上任何参数(我的第一篇文章 - 第 1 部分 / 我的第一篇文章 - 第 2 部分,...)

任何帮助将不胜感激。

I am creating a post, but it contains many paragraphs, and I wish that every post had no more than 5 paragraphs. That is, if my post has 15 paragraphs will automatically be divided into three posts.

Ex: I created the post titled "My first post" and he has 15 paragraphs. When sending to the database it will be divided into three posts of paragraphs 5, with different urls (site.com/my-first-post/page-1 - site.com/my-first-post/page-2 - site.com/my-first-post/page-3) and with the same title or plus any parameters (My first post - part 1 / My first post - part 2, ...)

Any help will be grateful.

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

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

发布评论

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

评论(1

苦笑流年记忆 2025-01-05 14:22:52

您正在寻找的概念是“分页”。

由于您尚未指定语言,因此无法为您提供任何代码。这是一个用 PHP 编写的示例(实际上来自 CodeIgniter 框架) http://codeigniter.com/forums/ viewthread/160280/

本质上,您将文章拆分为一个数组。中断元素是 EOL 字符(请小心处理 \r 和 \n)。然后,根据页面 id 拼接数组以获取数组的相关 5 个元素。

The concept you are looking for is 'pagination'.

Can't give you any code as you haven't specified a language. Here's an example written in PHP (it's actually from the CodeIgniter framework) http://codeigniter.com/forums/viewthread/160280/

Essentially, you split the article into an array. The break element is the EOL character (be carefully to handle \r and \n). Then you splice the array to take the relevant 5 elements of the array, based on the page id.

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