Support » Fixing WordPress » Determining body/page class

  • Resolved Cybjorg

    (@cybjorg)


    I’m trying to assign different CSS pages for only the blog pages of my template. I am using is_home() and is_single() conditional statements in the header in order to apply the custom style sheet to only those pages. The problem is that other pages in the site (portfolio pages) are also single posts. How can I filter out pages that also contain the “single-post” class in the body tag?

    Here’s what I have so far:

    <?php if ( is_home() || is_single() ) { ?>
        <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/skins/Dark.css" type="text/css" media="screen">
        <?php } elseif ((get_option_tree('theme_skin')) !== "Light") {	?>
        <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/skins/<?php echo get_option_tree( 'theme_skin' ); ?>.css" type="text/css" media="screen">
        <?php }	?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Are portfolio Posts a custom post type?

    if so, try:

    if ( 'portfolio' == get_post_type() ) ...

    http://codex.wordpress.org/Conditional_Tags#A_Post_Type

    Thread Starter Cybjorg

    (@cybjorg)

    I’m using a pre-built template, but the portfolio pages appear to be standard post types. I can’t find any functions registering a custom post type. The portfolio posts do have a body class of ‘single-portfolio’, so if there was a way to determine the body class, I could filter it out. I’m drawing a blank, however.

    Moderator keesiemeijer

    (@keesiemeijer)

    I think if it’s a normal Post the body class is ‘single-post’. If it’s a custom post type it will be ‘single-{post_type}’ as with your body class ‘single-portfolio’. Did you try the code I gave you?

    try also:

    if ( is_home() || ( is_single() && 'portfolio' == get_post_type())) {...

    Thread Starter Cybjorg

    (@cybjorg)

    Alright, I got it using your code. I was attempting to exclude the portfolio pages, so in the end I used this:

    if ( is_home() || (is_single() && 'post' == get_post_type()) ) {...

    Thanks so much for your help.

    Moderator keesiemeijer

    (@keesiemeijer)

    No problem. I’m glad you got it resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Determining body/page class’ is closed to new replies.