WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Determining body/page class (6 posts)

  1. Cybjorg
    Member
    Posted 2 years ago #

    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 }	?>
  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Are portfolio Posts a custom post type?

    if so, try:

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

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

  3. Cybjorg
    Member
    Posted 2 years ago #

    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.

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    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())) {...
  5. Cybjorg
    Member
    Posted 2 years ago #

    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.

  6. keesiemeijer
    moderator
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic