WordPress.org

Ready to get started?Download WordPress

Forums

CSS per page (8 posts)

  1. pixel
    Member
    Posted 9 years ago #

    Hey,
    I have searched around but I came up with nothing. I was wondering if anyone knows how to set up a custom field that is called css or something and the value being a additional css file to add into the header. But have a default one if nothing is put in the custom field. Here is a example:

    1. I post something on my blog, but do not do a custom field for the css, this post will not have a custom css file in the header. When someone goes to that post, it has the theme css template (the current theme style.css) and a default additional css template that adds a set of default classes.

    2. I post a page and fill in a field called css and then put the path to the additional css document in the value. When the viewer goes to that page, the page has the theme css template (the current theme style.css) and also another css template that adds a set of different classes (like header background img) instead of the default additional css template.

    On the index page only the default theme css template and the default additional css template would load.

    I hope this isn't too complicated to do... I would do it if I understood php, but I don't. ~_~. My blog is: http://www.bloonlabs.com. Tell me if this is possible. Thanks!

  2. moshu
    Member
    Posted 9 years ago #

    2. I post a page and ...
    Are we talking here about the Pages feature of WP or just posts?

  3. pixel
    Member
    Posted 9 years ago #

    Posts and pages. Sorry. ^_^

  4. Kafkaesqui

    Posted 9 years ago #

    (I seem to have stumbled upon a generic plugin framework that easily customizes for certain requests...)

    Pixel, I may have what you're looking for, that is a plugin that will grab the custom css value and match it to a stylesheet in the current theme's directory (then display the link tag for it in the <head> element). If instead you're using a separate directory for your post-specific stylesheets, let me know and I can make a small mod to it for that, as well as link to it here.

  5. pixel
    Member
    Posted 9 years ago #

    It will be in the same dir as the theme. Thanks so much! Please link it here, that would be brilliant. Will it allow a default linked css stylesheet? Like if I don't put a value in the custom field for the additional css style sheet can it automatically link a additional style sheet to the page? Thanks so much!

  6. pixel
    Member
    Posted 9 years ago #

    Bump ^_^

  7. Kafkaesqui

    Posted 9 years ago #

    Pixel, sorry about the delay. Was stuck on other things and forgot my offer. I apologize for that. Anyway, here finally is the plugin:

    http://guff.szub.net/wp-content/post-css.zip

    Two "user" variables at the top of the post_css() function in the plugin: $key, which is the custom field key you use for your stylesheets ('css' by default); $stylesheet_url, which if given a value overrides the plugin's search for the stylesheet in the active theme's directory (empty by default).

    Couple points:

    * You can assign more than one stylesheet to any post/Page.

    * The <?php wp_head(); ?> tag (a WP plugin hook) must be in a theme so the stylesheet link can be output to the <head> of the page. Just make sure the tag resides somewhere in the <head> portion of your template(s) -- typically header.php.

  8. RonR
    Member
    Posted 8 years ago #

    this plugin works great on the single-post page--thanks!

    is there a simple way to modify it so that it also includes -all- of the appropriate posts' stylesheets on multi-post pages (most importantly, the main page)?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.