WordPress.org

Ready to get started?Download WordPress

Forums

Custom CSS for Posts and Pages (CCSS)
how to apply stylesheet to subpages? (2 posts)

  1. guix69
    Member
    Posted 1 year ago #

    Hello Mr "Plugin Author" :)

    If you're still around, do you have any idea about how a stylesheet could be applied to a pages (works great) AND to its subpages?

    Thanks a lot
    G.

    http://wordpress.org/extend/plugins/custom-css-stylesheet-for-posts-or-pages/

  2. guix69
    Member
    Posted 1 year ago #

    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');
    	  }
    	}
     }
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags