Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Hi,

Is there any trick to limit max. number of posts in a template with clonable='1'

Thanks
Hi,

Try placing the following code in your 'addons/kfunctions.php' file (make sure to replace the 'options.php' => '3' within it with the actual name(s) of your templates and the max. allowed number(s)).

This will remove the 'Add New' button from the screen when the number of cloned pages for the indicated template surpasses the max value.
Code: Select all
// 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'] );
                }
            }
        }
    });
}

Hope this helps.
Do let me know.
Super..Working!!
Thank you KK

I have one more question, is it possible to use random with <cms:nested_pages depth='1', because I need to display random few posts from nested pages with depth 1 only.
A separate hook would be necessary to disable 'Copy to New' addon functionality.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
4 posts Page 1 of 1