Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-10-31 07:26:08
- krone1234
- New Member
- Registered: 2011-10-31
- Posts: 2
Different CSS-background for individual articles
Hello everybody
I’m actually creating my graphic-portfolio-website with TXP and would like to get individual body-css-backgrounds. For this I created a customfield (custom_bgcolor) which contains individual hex-codes. If the field is empty, a pre-defined color will appear. I embedded this in the page-header:
<txp:article form=“css_bg”/>
this is the forms’ content:
<txp:if_custom_field name=“custom_bgcolor”>
<STYLE type=“text/css”> body { background: <txp:custom_field name=“custom_bgcolor”/>;}</STYLE>
<txp:else />
<STYLE type=“text/css”> body { background: green;} </STYLE>
</txp:if_custom_field>
<txp:if_custom_field name=“custom_bgcolor”/>
This is a wrong solution, because it just displays a bunch of articles this way. Is there a clean working solution?
Thanks in advance
krone1234
Offline
Re: Different CSS-background for individual articles
Hi
there’s an extra <txp:if_custom_field name
at the end
Try
<txp:if_individual_article> <!-- check that you are in an individual article page -->
<txp:if_custom_field name="custom_bgcolor"> <!-- check if the custom field has a value -->
<style type="text/css"> body { background-color: <txp:custom_field name="custom_bgcolor"/>;}</style>
<txp:else /> <!-- if there is no value to the custom field use green background -->
<style type="text/css"> body { background-color: green;} </style>
</txp:if_custom_field>
<txp:else /> <!-- if you are in an article list page -->
<style type="text/css"> body { background-color: green;} </style>
</txp:if_individual_article>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline