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"]);
}
?>
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"]);
}
?>