Page 1 of 1

{PAGE_NUM} rep tag - for contentpart pagination

Posted: Wed 30. May 2007, 09:54
by jsw_nz
A wee snippet of code
to get page number in situations
where articles have 'paginated contentparts'

Returns -1 for single page (no pagination) or listing
and page number if the article does have paginated contentparts.
first page will be returned as 0, all else as integer 2,3, etc

frontend_render directory

Code: Select all

<?php 
/* ----------------------------------------------------------------------------------------
{PAGE_NUM}  replacement tag
* developed by jsw_nz for phpWcms  
* pulls equivalent of $content['aId_CpPage']
* uses {PAGE_NUM} 
* save as page_number.php in frontend directory
--------------------------------------------------------------------------------------------
*/
function get_page_num(){
	global $_CpPaginate; // sniff for pagination flag
	if($_CpPaginate == 1){
		$page_number = $GLOBALS["content"]['aId_CpPage']; 
	}else{
		$page_number = -1;
	} // end if
	return $page_number;
} // end function

if( ! ( strpos($content["all"],'{PAGE_NUM')=== false ) ) {
  $content["all"] = preg_replace('/\{PAGE_NUM\}/e','get_page_num();',$content["all"]);
 } 	
?>
I use this code to send via FlashVars in custom Flash Header
still guessing someone may find helpful for other situations as well
:)

UPDATE:

if needing total page count

Code: Select all

<?php 
/* ----------------------------------------------------------------------------------------
{PAGE_NUM}  replacement tag
* developed by jsw_nz for phpWcms  
* pulls equivalent of $content['aId_CpPage']
* uses {PAGE_NUM} save as page_number.php in frontend directory
--------------------------------------------------------------------------------------------
*/
function get_page_num($db){
	global $_CpPaginate; // sniff for pagination flag
	if($_CpPaginate == 1){
	   $article_id = $article_id ? $article_id : $GLOBALS["content"]["article_id"];
		$sql_cnt  = "SELECT DISTINCT IF(acontent_paginate_page=1, 0, acontent_paginate_page) AS acontent_paginate_page ";
		$sql_cnt .= "FROM ".DB_PREPEND."phpwcms_articlecontent WHERE ";
		$sql_cnt .= "acontent_aid=".$article_id." AND acontent_visible=1 AND acontent_trash=0 ";
		$sql_cnt .= "AND acontent_block IN ('', 'CONTENT') ORDER BY acontent_paginate_page DESC";
		$sql_cnt  = _dbQuery($sql_cnt);
		$total_pages = count($sql_cnt);
		$page_number = $GLOBALS["content"]['aId_CpPage']." of ".$total_pages; 
	}else{
		$page_number = -1;
	} // end if
	return $page_number;
} // end function

if( ! ( strpos($content["all"],'{PAGE_NUM')=== false ) ) {
  $content["all"] = preg_replace('/\{PAGE_NUM\}/e','get_page_num($db);',$content["all"]);
 } 	
?>
(straight from OliG's code)

Posted: Fri 1. Jun 2007, 07:57
by Oliver Georgi
little hint: Do not use preg_replace for simple replacement! Is slow.

Code: Select all

if(strpos($content["all"],'{PAGE_NUM}')!== false) {
  $content["all"] = str_replace{'{PAGE_NUM}',get_page_num(),$content["all"]);
}
Oliver

Posted: Fri 1. Jun 2007, 12:02
by jsw_nz
cheers Oliver
- always learning - :D