Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-01-15 19:21:57

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

[archived] ajw_custom_css: article-specific css

Notice: This thread is archived. This is now possible with native txp tags.

**********************************************************

Allows for conditional stylesheets on a per-article basis. Inspired by Khoi Vinh at Subtraction.

There are three small, non-hack prerequisites for this to function:

  • You must have a custom field available (defined in <em>textpattern/lib/admin_config.php</em>) in order to store the ‘true’ (<em>or any non-empty</em>) value, signaling that an article is using custom CSS.
  • You must name the CSS file according to the article ID number. For instance, article 63 would use 63.css.
  • You must store all the CSS files in the same location.

Download current version

Read documentation

Disclaimer: Ideally, this should/could be accomplished with Mark Norton’s mdn_if_custom plugin. But because that plugin is designed for use within articles and depends on variables that do not yet exist at the time non-article forms are parsed in Textpattern ($thisarticle & $pretext), this separate plugin was written and successfully sidesteps that issue. (please correct me if I’m wrong on that)

Last edited by Andrew (2007-01-23 06:06:27)

Offline

#2 2005-01-16 01:00:40

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,058
Website

Re: [archived] ajw_custom_css: article-specific css

Wow, thanks for that fast work.

I’ll download and test today.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#3 2005-01-16 01:25:44

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [archived] ajw_custom_css: article-specific css

Just as a note, it most likely will only work for individual articles and not for article lists (because there is no way to grab hold of that single article id if there are many articles listed on the page). So my guess is that it would work best with sites that implement the summary/excerpt article list and link to full individual articles.

Ideally, this whole thing should be doable in a completely different manner, i.e. by using an override form and utilizing the <code><txp:id /></code> value. But since override form is only meant for article forms, and it’d necessitate swapping out an unrelated form (or the page template), it’s just not possible.

Another method of doing this, which would probably work in all situations but be a little more-involved, would be to use a multipass plugin so that you can run back over the article after it’s been parsed. But I haven’t given it that much thought, so I’m not really sure.

Offline

#4 2005-01-16 03:17:54

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,058
Website

Re: [archived] ajw_custom_css: article-specific css

So, I did a very quick test (sunday morning, small kids in the house, …) and it works nicely indeed. Hmm, I had to check a bit how to use custom fields, had never used them so far -/.

A very good add on for TextPattern.

Ref your comment: if you want changes at site level more global), you’d probably want to edit you main stylesheet. But this is perfect if you want one article to have some special look, or, if you have one article that need additional styling that you don’t want to add to your main stylesheet. For example, if you use Textpattern as a CMS for a magazine like site.

Thanks for your nice work.

p./


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#5 2005-01-16 03:51:42

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [archived] ajw_custom_css: article-specific css

I updated it as per your comment, Philippe. Now accepts ‘media’ and ‘title’ as attributes.

Offline

#6 2005-01-16 08:43:14

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,058
Website

Re: [archived] ajw_custom_css: article-specific css

BTW – for sake of correctness – Khoi’s first name is ‘Khoi’ not ‘Koy’.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#7 2005-04-14 04:27:06

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [archived] ajw_custom_css: article-specific css

updated to v0.3 to clean up php error notices. i’ll update the link to download when the stupid forum works again someday.

Offline

#8 2006-08-17 09:38:38

sambody
New Member
From: Brussels, Belgium
Registered: 2006-08-10
Posts: 4
Website

Re: [archived] ajw_custom_css: article-specific css

Hi. I have installed the plugin and the help file is not readable for me: it puts all content on one line, with the original Textile code (h3. @ etc).

I don’t have this problem with other installed plugins. I guess it’s due to me using Markdown instead of Textile.

Could you use normal HTML for your help file ? I guess that would probably make it readable again.

Thank you.

Offline

#9 2006-08-18 04:34:24

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [archived] ajw_custom_css: article-specific css

That was actually a server issue (the parsing of Textile help happens on my end). It should be fixed now.

Offline

#10 2006-08-18 08:11:15

sambody
New Member
From: Brussels, Belgium
Registered: 2006-08-10
Posts: 4
Website

Re: [archived] ajw_custom_css: article-specific css

Andrew wrote:

That was actually a server issue (the parsing of Textile help happens on my end). It should be fixed now.

Ok, thanks.

Offline

#11 2007-01-21 23:45:52

Hans
Member
From: Everywhere
Registered: 2004-03-07
Posts: 99
Website

Re: [archived] ajw_custom_css: article-specific css

Andrew, I’m trying to implement this with an article that has an id of -31 (yes, that’s negative). It ain’t working… how might I fix this? Would I have to change the article id?


Lumilux – A Photoblog

Offline

#12 2007-01-22 02:28:51

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [archived] ajw_custom_css: article-specific css

Uh… good question :) I didn’t even realize it was possible to have a negative id. What exactly is the behaviour you’re seeing?

Offline

Board footer

Powered by FluxBB