Help - Search - Members - Calendar
Full Version: Different authors with diff colour text
Movable Type Community Forum > Additional Resources > Tips and Tricks
Chuckler
I had a requirement on my blog for each author to publish entries in different colours.

The ugly-but-working solution is to change the
CODE
<div class="blogbody">
line to
CODE
<div class="blogbody<$MTEntryAuthor$>">


And then copy the entire blogbody entry from the stylesheet with a different colour, and a new name, like this.

CODE
    .blogbodyChuckler {
 font-family:verdana, arial, sans-serif;
 color:#6666FF;
 font-size:small;
 font-weight:normal;
   background:#FFF;
   line-height:110%;  
   border-left:1px dotted #666;      
   border-right:1px dotted #666;
   border-bottom:1px dotted #666;            padding:10px;
 }


The question is: is there a more elegant way to do this? Sure, it works, but the Posted div thing will also need updating for each author, and the title is the wrong colour and I don't know how to fix that.

Anyone got an opinion?
trialanderror
This is a six of one and half a dozen of the other type solution using external css. Al-Muhajabah uses a similar technique.

The choices are maintaining multiple complete css (on a per author basis) or maintaining parts of a css (on a per author basis) This from the WDG spec.

CODE
A single style may also be given through multiple style sheets:

<LINK REL=StyleSheet HREF="basics.css" TITLE="Contemporary" TYPE="text/css">
<LINK REL=StyleSheet HREF="tables.css" TITLE="Contemporary" TYPE="text/css">
<LINK REL=StyleSheet HREF="forms.css" TITLE="Contemporary" TYPE="text/css">

In this example, three style sheets are combined into one "Contemporary" style that is applied as a preferred style sheet. To combine multiple style sheets into a single style, each style sheet's LINK must use the same TITLE.


So maintaining complete css per author means one link rel statement.
CODE
<LINK REL=StyleSheet HREF="<MTEntryAuthor>.css" TITLE="Authors" TYPE="text/css">


Maintaining partial css

CODE
<LINK REL=StyleSheet HREF="basics.css" TITLE="PerAuthor" TYPE="text/css">
<LINK REL=StyleSheet HREF="<MTEntryAuthor>.css" TITLE="PerAuthor" TYPE="text/css">


I had considered using the @import command, but I found that different browsers didn't always recognize importing css.

In terms of maintenance your solution and these suggestions have about the same amount of work involved in updating. At least with your solution, you only have to maintain one complete css. With this suggestion you have many. The trade-off is a you could have different layouts for each author as well as color schemes.

t&e
Lummox JR
A much better solution to my mind is to simply name the style for the author (I'd use the author nickname, though, and dirify it), and then create a div inside your blogbody.
CODE
<div class="blogbody">
<div class="<$MTEntryAuthorNickname dirify="1"$>">
...
</div>
</div>

The reason this is a better approach is that generally, blogbody should be a base style that authors vary from. It also allows you to more easily specify sub-styles.
CODE
.Chuckler {color:green}
.Chuckler .posted {color:#80C080}

.someone_else {color:indigo;font-family:"Comic Sans MS",script}
.someone_else h3.title {font-variant:small-caps}
.someone_else .posted {color:blue}

Lummox JR
Chuckler
Hey Lummox,

(a slight modification of) this works great, but I can't find any doco on what dirify does?

I ended up changing the index template to this:
CODE
<div class="blogbody">
<div class="<$MTEntryAuthor$>">
..
</div>
</div>


and the style sheet to this
CODE
.Chuckler {color:green}
.Bill {color:#80C080}

and removed the color: bits from .title, .blogbody and .posted.

It's awesome!
Lummox JR
The dirify filter is explained in the MT documentation along with the standard set of tags. It will remove spaces for you and convert to a directory-friendly format, which should also be CSS-friendly. If you get an author with a space in their name, it will make a difference.

Lummox JR
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.