Cách tạo phân trang tự động cho bài viết WordPress khi nội dung quá dài
>>Tham khảo thêm: TOP Theme WordPress tin tức mới nhất cực chất 2014
Phương thức làm việc như sau: đầu tiên là đếm ký tự bài viết. nếu bài viết vượt số ký tự ta quy định sẽ tự động thêm <!–nextpage–>.
đầu tiên bạn mở wp-includes/query.php tìm:
$pages=array($post->post_content);
$multipage=0;
thay đoạn đó thành:
$max_lex = 5000; // Tổng ký tự 1 trang
$string = $content;
$strrpos = mb_strrpos($content,” “);
$current = 0;
$pagesPost = ceil($strrpos/$max_lex);
$pagePost = 1;
if ($strrpos > $max_lex) {
$content = ”;
while ($current < $strrpos) {
$stringtt = mb_substr($string, $current, $max_lex);
$numStr = mb_strrpos($stringtt,” “);
if($pagePost<$pagesPost) $content .= $stringtt.“<!–nextpage–>”; else $content .= $stringtt;
$current = $numStr + $current;
$pagePost++;
}
} else {
$content = $string;
}
if ( $page > 1 ) $more = 1;
$multipage = 1;
$content = str_replace(“\n<!–nextpage–>\n”, ‘<!–nextpage–>’, $content);
$content = str_replace(“\n<!–nextpage–>”, ‘<!–nextpage–>’, $content);
$content = str_replace(“<!–nextpage–>\n”, ‘<!–nextpage–>’, $content);
$pages = explode(‘<!–nextpage–>’, $content);
$numpages = count($pages);
/* code by dinh quoc han & solitary */
Chúc các bạn thành công với Blog của mình.
Nguồn webbee.vn
Không có nhận xét nào:
Đăng nhận xét