Takeaway:

Whole network exclusive, real and effective Discuz! Post paging function, there are other online article module paging method, but there is no for the post. My own forum website need to do paging, helpless discuz official has not engage in paging, only their DIY wave. These days I also baidu a lot of information, just finally research out, now share the experience to everyone!

Steps:

1. Create a new directory namedcode.phpEntry file, the code is as follows:


      

/** * the newly added code.php entry file */

define('APPTYPEID'.2);
define('CURSCRIPT'.'code');

require './source/class/class_core.php';
require DISCUZ_ROOT.'./source/function/function_code.php';

/* Create and initialize objects */
$discuz = C::app();
$discuz->reject_robot();
$discuz->init();
/* Category array */
$modarray = array('1'.'2'.'3'.'4'.'5'.'6'.'7'.'8'.'9'.'10');
if(empty($_GET['mod') | |! in_array($_GET['mod'].$modarray)) {$_GET['mod'] = 'index';
}

/ * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- setting a constant -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
/*DIY module logo */
define('DIY_MOD'.$_GET['mod']);
/*DIY module ID (note: 495 below is the ID of my post DIY module, check method: in DIY mode, mouse over the module, the id value will be displayed in the upper right corner) */
define('DIY_BID'.isset($_GET['bid'])?$_GET['bid'] :495);
/* How many pieces of data are displayed per page */
define('DIY_SIZE'.isset($_GET['size'])?$_GET['size'] :10);
/ * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /

/* Execute hook */
runhooks();

/* Forum description */
$navtitle = str_replace('{bbname}'.$_G['setting'] ['bbname'].$_G['setting'] ['seotitle'] ['code']);
$_G['disabledwidthauto'] = 1;

/* Steering controller */
require_once libfile('code/index'.'module');
? >
Copy the code

2, source\function\ create function_code. PHP ****


      
/** * define different mod methods */
if(! defined('IN_DISCUZ')) {
	exit('Access Denied');
}

? >
Copy the code

3. Create ****code folder under source\module\ and create ****code_index.php in code folder.


      
/** * Back-end controller */
if(! defined('IN_DISCUZ')) {
	exit('Access Denied');
}

list($navtitle.$metadescription.$metakeywords) = get_seosetting('portal');
if(!$navtitle) {
	$navtitle = $_G['setting'] ['navs'] [1] ['navname'];
	$nobbname = false;
} else {
	$nobbname = true;
}
if(!$metakeywords) {
	$metakeywords = $_G['setting'] ['navs'] [1] ['navname'];
}
if(!$metadescription) {
	$metadescription = $_G['setting'] ['navs'] [1] ['navname'];
}

/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = paging start = = = = = = = = = = = = = = = = = = = = = = = = = = = = / /
require_once libfile('function/discuzcode');
require_once libfile('function/home');
//DIY module identifier
$mod=DIY_MOD;
/ / DIY module id
$bid=DIY_BID;
// Display the number of entries per page
$perpage = DIY_SIZE;
// The maximum number of pages allowed to display
$maxpages  = 0; 
// What is the maximum number of pages to display? Hidden)
$page  = 10; 

// The number of records
$count = C::t('code')->fetch_count_sql($bid);
if($count>0) {// Count the total pages
	$totalPage =  (int) (($count + $perpage -1) / $perpage); 

	// Page control
	$curpage = isset($_GET['page'])?$_GET['page'] :1;
	if($curpage<1) $curpage = 1;
	if($totalPage< (int)$curpage) $curpage = $totalPage;

	// Start recording
	$start = ($curpage-1) *$perpage;
	// paging judgment
	ckstart($start.$perpage);  

	// This array is used to display the number of pages
	$pageArray=array(a);for ($i=1; $i< =$totalPage; $i++)
	{
		array_push($pageArray.$i); }}// Jump path
$mpurl = 'code.php? mod='.$mod.'&bid='.$bid; 
// Last page, automatic jump
$autogoto = FALSE;
// Clean mode (clean mode does not display previous page, next page, and page number jumps)
$simple = FALSE; 
/ / paging
$multipage = multi($count.$perpage.$curpage.$mpurl.$maxpages , $page.$autogoto.$simple); 
/** * The paging function multi ()@param$count - Total number *@param$perPage - Number of pages *@param$curPage - Current page *@param$mpurl - Jump path *@param$maxPages - Maximum number of pages allowed to be displayed *@param$page - What is the maximum number of pages to display? Hidden) *@param$autogoto - Last page, automatic jump *@param$simple - Whether concise mode (concise mode does not show previous page, next page, and page number jumps) *@return- Returns the paging code */
/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = paging end = = = = = = = = = = = = = = = = = = = = = = = = = = = = / /
// Jump to the front view
include_once template('diy:code/'.$mod);
? >
Copy the code

> source > class > table > create ****table_code.php


      
require_once libfile('function/home');
/** * code.php */

if(! defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class table_code extends discuz_table
{
	public function __construct() {

		$this->_table = 'common_block_item';/ / the name of the table
		$this->_pk    = 'itemid';		    // Primary key of the table

		parent::__construct();
	}
	// Query the total number of records
	public function fetch_count_sql($bid) {
		$where="where bid=".$bid." ORDER BY itemid DESC";
		return DB::result_first('SELECT COUNT(*) FROM %t %i '.array($this->_table, $where));
	}
	// Query data
	public function fetch_all_by_sql($start.$limit.$bid) {
		return DB::fetch_all('SELECT * FROM %t where bid='.$bid.' ORDER BY itemid DESC'.DB::limit($start.$limit), array($this->_table)); }}? >
Copy the code

5, open ****table_common_block_item. PHP under \source\class\table\. Find ****function fetch_all_by_bid($bids, $sort = false) and change it to the following code:

	public function fetch_all_by_bid($bids.$sort = false) {
		$sql='SELECT * FROM '.DB::table($this->_table).' WHERE '.DB::field('bid'.$bids). ($sort ? ' ORDER BY displayorder, itemtype DESC' : ' ORDER BY itemid DESC');
		/ * = = = = = = = = = = = = = = = = = = = = = = = = = = = post module increase paging start = = = = = = = = = = = = = = = = = = = = = = = = = * /
		if(in_array(DIY_BID,$bids)) {/* Get the current page */
			$page = isset($_GET['page'])?$_GET['page'] :0;
			if($page<1) {$page=1;
			}
			/* How many pages are displayed per page */
			$limit=DIY_SIZE;
			/* Start recording */  
			$start = ($page-1) *$limit;
			$sql.=DB::limit($start.$limit);
			/* runlog(" SQL "," SQL statement: ".$SQL); * /
		}	
		/*=================================== end ======================================*/	
		$result=DB::fetch_all($sql.null.$this->_pk);
		return $result;
	}
Copy the code

Create ****code under the template\default\ directory and create ****index.htm in the code folder as follows:

<! --{template common/header}-->
<style id="diy_style" type="text/css"></style>
<style type="text/css">
body{ background:#F6F7F9! important; }.wp.#wp{ width:100%; }.nexwp{ width:1180px; margin:20px auto 0 auto; }
.nex_portbox{ margin-top:20px; }.nex_portbox ul{ width:1205px; }.nex_portbox ul li{ float:left; width:223.2 px.; margin:0 16px 16px 0; background:#fff; box-shadow: 0 2px 3px rgba(0.0.0.0.06); -webkit-transition:all 0.3 slinear; -moz-transition:all 0.3 slinear; -o-transition:all 0.3 slinear; -ms-transition:all 0.3 s linear;transition:all 0.3 s linear;border-radius:0 0 4px 4px; }.nex_LG_piv a{ display:block; width:223.2 px.; height:167px; position:relative; }.nex_LG_piv a img{width:223px; height:167px; border-radius:4px 4px 0 0; }.nex_portbox ul li:hover .nex_LG_piv a img{ opacity:0.8; }.nex_LG_info{ border-bottom: 1px solid #ededed; padding: 11px 16px 13px; height: 75px; position: relative; }.nex_LG_info h5{ height:22px; line-height:22px; overflow:hidden; }
.nex_LG_info h5 a{ font-size: 14px;color: # 333; font-weight:400; }.nex_LG_info h5 a:hover{ color:#0EC5A1; }.nex_LG_type{ font-size: 12px; color: #bbb; margin-bottom: 17px; height: 18px; }.nex_LG_item span{font-size: 12px; color: #bbb;margin-right: 10px; padding-left:25px; }.nex_LG_item span.nex_statistics_view{ background:url(./template/wfdsoft_freegift_171220/neoconex/portal_list_view/viewx.png) left center no-repeat; }.nex_LG_item span.nex_statistics_comment{ background:url(./template/wfdsoft_freegift_171220/neoconex/portal_list_view/reply.png) left center no-repeat; }.nex_LG_btms{height: 24px; line-height: 24px; padding: 14px 16px; font-size: 12px; border-radius:0 0 4px 4px; position: relative; }.nex_LG_btms a{ display:block; float:left; }.nex_LG_btms a img{ width:24px; height:24px; border-radius:100%; display:block; float:left; }.nex_LG_btms a em{ display:block; float:left; margin-left:10px; height:24px; line-height:24px; font-size:12px; color:# 333; }.nex_LG_btms a:hover em{ color:#0EC5A1; }.nex_LG_btms span{ display:block; width:70px; overflow:hidden; text-align:right; float: right; font-size:12px; color:#bbb; height:24px; line-height:24px; }.nex_LG_txts{ height:30px; line-height:30px; margin-bottom:20px; font-size:16px; color:# 666; font-weight:400; }.nex_LG_Links ul{ width:1205px; }.nex_LG_Links ul li{ float:left; width:223.2 px.; margin:0 16px 16px 0; background:#fff; box-shadow: 0 2px 3px rgba(0.0.0.0.06); -webkit-transition:all 0.3 slinear; -moz-transition:all 0.3 slinear; -o-transition:all 0.3 slinear; -ms-transition:all 0.3 s linear;transition:all 0.3 s linear;border-radius:0 0 4px 4px; }.nex_LG_Links ul li:hover .nex_LG_piv a img{ opacity:0.8; }.nexads{ width:1180px; margin:10px 0; }.nexads img{ width:1180px; }.nexpubtop {
    height: 38px;
    margin-bottom: 20px;
}
.nexpubtop span {
    display: block;
    float: left;
    padding-left: 45px;
    height: 38px;
    line-height: 38px;
}
.nexpubtop ul {
    float: right;
    margin-top: 6px;
}
.nexpubtop ul li.cur {
    background: #0EC5A1;
    color: #fff;
    border: 1px solid #0EC5A1;
}
.nexpubtop ul li {
    float: left;
    padding: 0 18px;
    margin-left: 10px;
    border: 1px solid #ededed;
    height: 25px;
    line-height: 25px;
    border-radius: 2px;
    font-size: 14px;
    color: # 666;
    cursor: pointer;
}
.nexsucaibox ul{display:none; }</style>
<div class="nexwp">
	<div id="pt" class="bm cl">
        <div class="z">
            <a href=". /" class="nvhm" title="{lang homepage}">$_G[setting][bbname]</a> <em>&rsaquo;</em>All categories</div>
    </div>
        	<div class="nexpubtop">
                <ul>
				    <li class="cur"><a href="code.php? bid=495">All categories</a></li>
                	<li><a href="code.php? mod=1&bid=496">Classification of a</a></li>
                    <li><a href="code.php? mod=2&bid=497">Category 2</a></li>
                    <li><a href="code.php? mod=3&bid=498">Classification of three</a></li>
                    <li><a href="code.php? mod=4&bid=499">Classification of the four</a></li>
                    <li><a href="code.php? mod=5&bid=500">Classification of five</a></li>
                    <div class="clear"></div>
                </ul>
                <div class="clear"></div>
            </div>
			<div class="nexsucaibox nex_LG_Links">
				<ul style="display:block;">
				<! --[diy=nex_code_list1]--><div id="nex_code_list1" class="area"></div><! --[/diy]-->
				<div class="clear"></div>
				</ul>
            </div>
			<script type="text/javascript">
				// Toggle navigation
				jq(".nexpubtop ul li").each(function(s){
					jq(this).click(function(){
						jq(this).addClass("cur").siblings().removeClass("cur"); })});</script>	
    <div class="clear"></div>
	<! - page - >
	<div class="pgs cl">
	<! --{if $multipage}-->$multipage<! --{/if}-->
	</div>
</div>
	
<div class="nexwp">  
    <div class="nex_LG_txts">Guess you like</div>
    <div class="nex_LG_Links">
    	<ul>
        	<! --[diy=nex_LG_Links]--><div id="nex_LG_Links" class="area"></div><! --[/diy]-->
        	
            <div class="clear"></div>
        </ul>
    </div>
    <! --ads-->
    <div class="nexads">
    	<div class="w1180">
        	<! --[diy=nexads]--><div id="nexads" class="area"></div><! --[/diy]-->
        	
        </div>
    </div>
</div>

<! --{template common/footer}-->
Copy the code

$_config[‘memory’][‘redis’] $_config[‘memory’][‘redis’] $_config[‘memory’][‘redis’]

// -------------------------- CONFIG MEMORY --------------------------- //
/*-- It is not recommended to enable redis cache, because once enabled, the paging can not be displayed in real time. - * /
$_config['memory'] ['prefix'] = 'uXJfik_';
/ / $_config [' memory '] [' redis] [' server '] = '127.0.0.1';
$_config['memory'] ['redis'] ['server'] = ' ';
$_config['memory'] ['redis'] ['port'] = 6379;
$_config['memory'] ['redis'] ['pconnect'] = 1;
$_config['memory'] ['redis'] ['timeout'] = '0';
$_config['memory'] ['redis'] ['requirepass'] = ' ';
$_config['memory'] ['redis'] ['serializer'] = 1;
$_config['memory'] ['memcache'] ['server'] = ' ';
$_config['memory'] ['memcache'] ['port'] = 11211;
$_config['memory'] ['memcache'] ['pconnect'] = 1;
$_config['memory'] ['memcache'] ['timeout'] = 1;
$_config['memory'] ['apc'] = '0';
//$_config['memory']['apcu'] = '1';
$_config['memory'] ['apcu'] = '0';
$_config['memory'] ['xcache'] = '0';
$_config['memory'] ['eaccelerator'] = '0';
$_config['memory'] ['wincache'] = '0';
$_config['memory'] ['yac'] = '0';
//$_config['memory']['file']['server'] = 'data/cache/filecache';
$_config['memory'] ['file'] ['server'] = ' ';

// -------------------------- CONFIG SERVER --------------------------- //
Copy the code

That’s it, Oh yeah! All codes have made detailed remarks, I hope to be useful to you. You should pay attention to how the logic is written when referring to other people’s code. Welcome to visit my website to see the effect.zy13.net/code.php