Support » Themes and Templates » CSS Question for Static Pages, Landing Page & Blog Posts

  • Resolved Nina Morena

    (@ninamorena)


    I am currently building a website and I need three separate page types. So far I have been successful within my template using the basic style.css and inner.css for the landing page and the basic site page templates. I would like all blog posts to have a different template but I am not sure where I apply the page template for the blog post itself. I have used the following code in my header but it is not working in this particular instance:

    <?php if ( is_page_template('index.php')) { ?> <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/inner.css" /><?php } ?>

    I have used single.php with the same result.

    Ultimately, I would like a separate stylesheet for the blog post itself, where do I add this in the header?

Viewing 6 replies - 1 through 6 (of 6 total)
  • xdesi

    (@xdesi)

    You would like a seperate stylesheet for single blog post pages?

    This would do that:

    <?php if(is_single()){ ?>
    link to stylesheet
    <?php } ?>
    Nina Morena

    (@ninamorena)

    Xdesi,

    That worked perfectly! I think the only thing left for me is the blog page where the most recent post appear. They too should have the same stylesheet.

    xdesi

    (@xdesi)

    What’s the blog page, we need a way of distinguishing this? Is it your homepage, your frontpage?

    One of these two might do the trick if it is either of those.

    <?php if(is_single() || is_home()){ ?>
    link to stylesheet
    <?php } ?>
    
    <?php if(is_single() || is_front_page()){ ?>
    link to stylesheet
    <?php } ?>
    Nina Morena

    (@ninamorena)

    The actual blog page is my news page. The site has several static pages including the homepage that I’ve used WordPress strictly for content management. Since the owner is going to post multiple news stories, I figured it would be a good idea to use the News section as the actual post/blog pages for the site. In the Settings>Reading section, you can point the posts pages to a default page. In this case, I used the “News” section. So my last three post appear when the user clicks “News” but the style sheet does not apply that I’d like to use.

    I hope I made sense.

    xdesi

    (@xdesi)

    Yeah did you try the is_front_page() because that might apply here from how you’ve explained, although you can also do something like:

    <?php if(is_single() || is_page('news')){ ?>
    link to stylesheet
    <?php } ?>

    Change the word “news” to the exact name of the page in question if it’s not news, or you can change it to the page ID whichever you prefer!

    So the code basically says if the page is a single post page, or is the news page display the link to the stylesheet.

    WP has tons of conditional tags like this so it’s very easy to do! You can see here for more info:
    http://codex.wordpress.org/Conditional_Tags

    Nina Morena

    (@ninamorena)

    Thanks Xdesi.

    I ended up using Conditional Tags for all post tagged “news”.

    `<?php if ( has_tag(‘news’)) { ?> <link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘template_directory’); ?>/inner.css” /><?php } ?>”

    Thanks for pointing me in the right direction.

    xo

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘CSS Question for Static Pages, Landing Page & Blog Posts’ is closed to new replies.