• Resolved maujor

    (@maujor)


    Hi all
    I spent hours searching the WP site for a way to stylize a single post but all i’ve found was nothing! πŸ™
    I’m a CSS expert and would like to know; is this possible?
    Create a page template with its style sheet is easy, but I want a page post linked to the the site’s CSS and a custom CSS.
    Please, no inline styles solutions
    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Well, rather than create a new css sheet, I’d say create a new copy of your regular page template, and just change the div class or id that surrounds the php functions that call the page post.

    That would let you add the css to the main style sheet.

    I’ve done that and it worked great for me, but I’m no pro, so this might not be the best way.
    πŸ™‚

    Thread Starter maujor

    (@maujor)

    If I’ve understood what you point out, this solution will load irrelevant CSS (the rules for one page only) in all pages of the blog. Is this?

    Shouldn’t single.php work for you? That’s tha template file for single posts.
    http://codex.wordpress.org/Template_Hierarchy

    Thread Starter maujor

    (@maujor)

    Hi moshu,
    Thank you for your kindness suggestion.
    Sorry! single.php is used for all single posts.
    This template call the posts header via <?php get_header(); ?>
    If I put the link calling my custom style sheet into that header.php, i’ll load irrelevant css in all posts.

    Let me do a comparison with javascript:
    Using javascript
    When you need a javascript script working in one single post you must:

    1. create a js file containing the js function;
    2. link to that file in the header.php;
    3. call the js function into the <body> of the post where you want the function working

    For CSS isn’t a way for call the style sheets in the <body>
    So the problem is: How to customize a header.php for a single post. (not a page – this is easy).
    I suspect that this is not possible to achieve with the actual WP tools/templates.

    I got it. So you want only certain single posts to be styled differently, right?
    Is there anything in common for those posts? (like being in the same category, subcategory?)

    wow, this is a highly unusual request.

    First, note that CSS gets cached. So, despite it being ‘irrelevant’ to other pages/posts, having it be in one file makes many things easier (only one to download ever, always the same one…).

    Second, the ‘conditional’ solution can be achieved a few ways. By the time you reach your header.php, the query has run. $p >might< be set to the post Id. if not, the query should have detected is_single, and will be able to give you the post id.

    With the post id retrieved into a variable at the top of say header.php, there’s a few approaches:

    1. if the post ID matches the custom one, include the custom css instead of the standard css. that’s pretty simple. You could completely change the style, though the basic components of the theme remain.

    2. set the ID of the body or first div to “post-“.$postID (where $postID is the thing you grab at the top). In the CSS, you can then have targeted overrides for just that post. But again, then only really need one CSS file. Overhead should be minimal.

    3. write a custom plugin that pulls up a custom theme when that single post is the query result. then you can modify both theme AND css to your complete needs.

    -d

    Thread Starter maujor

    (@maujor)

    Hi moshu,
    Hello davidchait,

    Great thoughts! Problem solved! Thanks a lot.
    —————————————————–
    Lets add some items more:
    1-)[quote=davidchait]First, note that CSS gets cached. ….).[quote]
    Yes, I do agree tottaly. But, I’ll have not a few customize posts, I’m talking for 100+ posts, and styles sheet for 100+ pages into a single style sheet wow!!! will be a nightmare and a big one πŸ™‚

    2-)[quote=davidchait]Second, the ‘conditional’ solution can…).[quote]
    Interesting way for walk across, I do not test it because:

    the link pointed by moshu wordpress.org/support/topic/27073?replies=29
    put the light over the question.
    In that thread Ryan answering a question, told he had developed a Plugin named Custom post template. Few PHP lines, in a smart fashion that works like a charm not only for posts (the subject of my search) but for categories too.
    ——————————————————
    Further explanations
    For others members and future references for the same subject I’d like add some explanations:

    After installed and actived the Ryan’s plugin to customize the post, e.g. ID=27
    1- make a copy of single.php and name it single-27.php;
    2- on single-27.php replace <?php get_header();?> by <?php include 'header-27.php'); ?>;
    3- make a copy of header.php and name it header-27.php`
    4- customize header-27.php and you are ready to go.

    Each post id=# must have their single-#.php/header-#.php

    For category customization see comments inside Ryan’s plugin.

    Hello forum moderators: if the further explanations above are confusing (sorry for the poor english) feel free to edit or throw away. πŸ™‚

    Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘CSS for a single post’ is closed to new replies.