Share Tự động phân trang bài viết WordPress khi quá dài

Tuzoro

Tuzoro

New Member
Mình sẽ hướng dẫn các bạn cách làm.
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:
PHP:
		$pages = array( $post->post_content );
		$multipage = 0;
thay đoạn đó thành:
PHP:
	$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 */
Hoặc coppy toàn bộ tệp query tại đây: jquery.php

Chúc bạn thành công
nguồn SieKuTi
 

Facebook Comments

Similar threads

Admin
Replies
0
Views
2K
AdminAdmin is verified member.
Admin
Admin
Replies
1
Views
1K
N
Admin
Replies
0
Views
1K
AdminAdmin is verified member.
Admin
cuongpro9x
Replies
1
Views
1K
vietpro2008
V
Admin
Replies
0
Views
2K
AdminAdmin is verified member.
Admin
Back
Top