Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-03-25 14:35:21
- daphna
- Member
- Registered: 2009-02-22
- Posts: 18
question regarding specific styles for articles in pages
im trying to build my first textpattern site these days.
its a sort of complicated portfolio.
the client wants one of the sections to be this:
when u enter the section u get logos of different clients of his, and then every logo leads to an independent article that shows a gallery of the work done for that client.
and the style changes in between the “welcome to” and each “client page”.
basically my question is this. is there a way to make articles have a certain style, that is different of their “master-section”, or even better Is There A Way To Create a Section Within a Section ?
Offline
#2 2009-03-25 17:57:23
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: question regarding specific styles for articles in pages
You could use a custom field:
Name a custom field for instance ‘style’. For the articles that need a different style, place the name of the css in the custom field. Then in the head section of your page, after the link to the regular css, add this:
<txp:if_section name="your-section-name">
<txp:if_individual_article>
<txp:if_custom_field name="style">
<txp:css format="link" n='<txp:custom_field name="style" />' />
</txp:if_custom_field>
</txp:if_individual_article>
</txp:if_section>
Or you could add an id to the html body tag:
<txp:if_section name="your-section-name">
<txp:if_individual_article>
<txp:if_custom_field name="style">
<body id="<txp:custom_field name="style" />">
<txp:else />
<body>
</txp:if_custom_field>
</txp:if_individual_article>
</txp:if_section>
You can do something similar using a catagory instead of a custom field.
Offline
#3 2009-03-26 13:18:45
- daphna
- Member
- Registered: 2009-02-22
- Posts: 18
Re: question regarding specific styles for articles in pages
using the categories actually seems most convenient
(im not sure i understand the custom field thing)
so i can just tell a certain category to get a different style then?
Offline
Re: question regarding specific styles for articles in pages
Although Els is our beloved Queen of Tags combination, and Her Majesty always came up with a clever and/or simple solution, I think this time she has overly complicated it.
But I must also admit that it’s not clear (at least for me) your request.
Are there just one “section” style and one “article” style?.
In this case, could this be enough?
<head>
....
<txp:if_article_list>
<!-- we're are on a section, probably -->
...link to "section" stylesheet...
<txp:else />
<!-- we're are on an individual article, definitely -->
...link to "article" stylesheet...
</txp:if_article_list>
...
</head>
Or does each “client page” have to have a unique style? (that is, a unique stylesheet)?
In this case, you may want to try a similar approach to the one suggested by Els:
<body class="<txp:article_url_title />">
That is enough to have a unique class per article, and that’s enough to do custom styling for each article on a single stylesheet.
Of course, you may also want to play with some conditionals like if_article_list
(or its reflection: if_individual_article
) and if_article_id
and a few other that will help you fine tune the output to your needs.
Last edited by maniqui (2009-03-26 13:42:56)
Offline
#5 2009-03-26 15:25:23
- daphna
- Member
- Registered: 2009-02-22
- Posts: 18
Re: question regarding specific styles for articles in pages
im not sure how idiotic im coming off here, but nevermind:)
so first – clarification :
my wish is that the first article in the section will have the same style as the rest of the site.
(or not be an article at all for all i care…just a kind of “welcome to the “works’ section and here are links to all the articles of this section”)
the articles within that “03_works” section will all have the same style as each other, but that style will be different then the rest of the site’s style.
______________________________________________
now…
main problem is that i don’t comprehend so it seems what exactly an “article list” is or what the “individual article” tag is.
i’m confused out of my mind.
IF There is a way to simply use the categories? i think that would be best. cause then every time i want an article in “the special style” i would just give it that category and get it over with.
i tryed changing “custom field” part to category in that previous code Els gave, but that made the dislpay blank so i guess i got it wrong.
this might be too much for a forum guidance, i know, but if u think its explainable that would be great.
Offline
Re: question regarding specific styles for articles in pages
Hey, no problem, you will get it soon (the “click” in your mind).
First, to understand the difference between an “article list” and an “individual article”.
If you have set your URL mode to /section/title
, then:
- if you are at an URL like this: http://www.example.com/section/, you are looking at a section. A section is just an “article list” context.
- if you are at an URL like this: http://www.example.com/section/my-article, you are looking at an article, and you are in “individual article” context.
So, a section is an article list, and an article is an individual article.
FYI, there are other “article list” contexts: the home (aka “default” section), or a category (http://www.example.com/section/?c=my-category).
But there is just one “individual article” context: the article itself, on its own URL (aka “permanent link” or “permlink”).
Those are the two context in TXP: or you are at an article list (section, home, category) or you are at an individual article.
There isn’t any other context.
Let’s go on.
So, with just txp:if_article_list
or txp:if_individual_article
you can test if you are in any of those two context.
This:
<txp:if_article_list>
I'm in a list of article, so do this and that
<txp:else />
I'm looking at an individual article. Do this and that.
</txp:if_article_list>
is the same than this:
<txp:if_individual_article>
I'm looking at an individual article. Do this and that.
<txp:else />
I'm in a list of article, so do this and that
</txp:if_individual_article>
So, in your page template for section “works”, you could try something like this:
<txp:if_article_list>
<!-- we are on the section root (aka, "article list" context) -->
Welcome to the Works section. This is where blablablaba... (add HTML, etc)
<txp:else />
<!-- we are in the individual article context!
Let's display one article belonging to this section. -->
<txp:article />
</txp:if_article_list>
Last edited by maniqui (2009-03-26 16:17:16)
Offline
#7 2009-03-26 16:25:27
- daphna
- Member
- Registered: 2009-02-22
- Posts: 18
Re: question regarding specific styles for articles in pages
nice! weekend starts here in a couple of minutes, but i think i got it (in theory at list). and ill try and make it work soon..and report back..Thank You very much!
Offline
Re: question regarding specific styles for articles in pages
I often (always, actually) employ the tactic of inserting the section name into a class of the body – then you can customize styles for each section to your heart’s content. You could do the same with article categories on individual article pages (if for example each client was a category), I suppose.
Something like
<body class="<txp:section />Body<txp:if_individual_article> <txp:category 1 /></txp:if_individual_article>">
Or you can use id’s instead.
Offline