2024年04月18日 建站教程
the_content()代码:<?php
// 获取当前文章
$post = get_post($post->ID);
// 获取文章内容
$content = $post->post_content;
// 定义每页显示的内容长度
$content_per_page = 2500;
// 计算总的页面数量
$total_pages = ceil(strlen($content) / $content_per_page);
// 获取当前页码
$current_page = get_query_var('page');
// 如果不存在当前页码,则设置为第一页
if (!$current_page) {
$current_page = 1;
}
// 计算当前页的内容起始位置
$start = ($current_page - 1) * $content_per_page;
// 截取当前页的内容
$content_part = substr($content, $start, $content_per_page);
// 输出当前页的内容
echo $content_part;
// 输出分页导航
for ($i = 1; $i <= $total_pages; $i++) {
$current_page = ($i == $current_page) ? 'current-page' : '';
echo '<a href="' . get_permalink() . '?page=' . $i . '" class="' . $current_page . '">' . $i . '</a>';
}
?>
根据需要调整$content_per_page变量来控制每页显示的内容长度。然后,在适当的位置调用这个代码片段即可将文章分为多个页面,并显示分页导航。
本文链接:http://so.lmcjl.com/news/2496/