ThemeShaper Forums » Thematic

[closed]

Custom CSS for some pages & custom post types

(3 posts)
  • Started 9 years ago by torsteino
  • Latest reply from em hr
  • This topic is not resolved
  1. Hi,
    I need to switch to a different stylesheet on some of the pages on a site I'm working on.

    The "is_tree" function and the first "if" works fine, switching to the first alternate stylesheet, but by some reason nothing happens with the "elseif" (should be for all posts of a custom post type using this page template), and only the default stylesheet loads.

    Can anyone see some kind of reason why it doesnt work, and if so - be so kind as to explain why?

    function is_tree($pid) {      // $pid = The ID of the page we're looking for pages underneath
    	global $post;         // load details about this page
    	$anc = get_post_ancestors( $post->ID );
    	foreach($anc as $ancestor) {
    		if(is_page() && $ancestor == $pid) {
    			return true;
    		}
    	}
    	if(is_page()&&(is_page($pid)))
                   return true;   // we're at the page or at a sub page
    	else
                   return false;  // we're elsewhere
    };
    
    function styleswap() { ?>
    <?php if(is_tree('3') ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('home'); ?>/wp-content/themes/mytheme/alternate1.css" type="text/css" media="screen" />
    <?php } elseif(is_page_template('single-productions.php') ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('home'); ?>/wp-content/themes/mytheme/alternate2.css" type="text/css" media="screen" />
    <?php } else { ?>
    <link rel="stylesheet" href="<?php bloginfo('home'); ?>/wp-content/themes/mytheme/style.css" type="text/css" media="screen" />
    <?php } ?>
    <?php }
    add_filter('thematic_create_stylesheet','styleswap');
    Posted 9 years ago #
  2. Ok, I found the solution on my own:

    It seems that is_page_template doesnt work on custom post types, you must use is_singular('name_of_custom_post_type')

    Posted 9 years ago #
  3. Thank you so much for sharing your solution. That is very helpful.

    -Gene

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.