Hi,
Is there any trick to limit max. number of posts in a template with clonable='1'
Thanks
Is there any trick to limit max. number of posts in a template with clonable='1'
Thanks
// limit max. number of pages
if( defined('K_ADMIN') ){ // if admin-panel being displayed ..
$FUNCS->add_event_listener( 'alter_pages_list_toolbar_actions', function(&$arr_actions, &$obj){
global $FUNCS, $PAGE, $DB;
/* place the names of templates with their max allowed pages here */
$tpls = array(
'options.php' => '3',
);
$route = $FUNCS->current_route;
if( is_object($route) && $route->module=='pages' && $PAGE->tpl_is_clonable && array_key_exists($PAGE->tpl_name, $tpls) ){
$max_pages = (int)$tpls[$PAGE->tpl_name];
$rs = $DB->select( K_TBL_PAGES.' p', array('count(p.id) as cnt'), "p.template_id='".$PAGE->tpl_id."' AND p.parent_id=0" );
$total_rows = $rs[0]['cnt'];
if( $total_rows >= $max_pages ){
if( array_key_exists('create_new', $arr_actions) ){ // remove 'Add New' button
unset( $arr_actions['create_new'] );
}
}
}
});
}