Support » Plugin: Custom CSS for Posts and Pages (CCSS) » how to apply stylesheet to subpages?

Viewing 1 replies (of 1 total)
  • Here is the answer in case someone needs it 🙂

    function ccss_save() {
    	global $post_ID;
    
    	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
    	if (!current_user_can( 'edit_post', $post_id ) ) return;
    
    	$id = $_POST['post_ID'];
    	$css_sheet = $_POST['ccss'];
    
    	// no need to keep extra info in db for posts/pages without an extra stylesheet.
    	if ($css_sheet != '-1') {
     	update_post_meta($id, 'css_sheet', $css_sheet);
    
    	// adds style to subpages
     	$args=array(
      		'child_of' => $id
    	);
    	$pages = get_pages($args);
    	if ($pages) {
    	  $pageids = array();
    	  foreach ($pages as $page) {
    	  	update_post_meta($page->ID, 'css_sheet', $css_sheet);
    	  }
    	}
     }
     else {
      delete_post_meta($id, 'css_sheet');
    	// removes style from subpages
     	$args=array(
      		'child_of' => $id
    	);
    	$pages = get_pages($args);
    	if ($pages) {
    	  $pageids = array();
    	  foreach ($pages as $page) {
    	  	delete_post_meta($page->ID, 'css_sheet');
    	  }
    	}
     }
    }
Viewing 1 replies (of 1 total)
  • The topic ‘how to apply stylesheet to subpages?’ is closed to new replies.