Per Post CSS

1 view
Skip to first unread message

ACME Media Farm

unread,
Aug 17, 2010, 10:19:24 AM8/17/10
to habari-users
Hello Everyone. I understand that you can use a different template for
each of your posts, but I couldn't find any information abut per
post .css - is it possible to have a different template and .css for
each post?

Thanks!

Owen Winkler

unread,
Aug 17, 2010, 8:37:46 PM8/17/10
to habari...@googlegroups.com

It depends how your theme is configured.

If your theme is set up like any of the core themes, you can add a
couple of lines before the first line of the file, which is the line
that displays the head section of the output page.

<?php
if($request->display_entry && isset($post)) {
Stack::add('template_stylesheet',
array(
Site::get_url('theme', '/entry-' . $post->id . '.css'),
'screen')
);
}
?>

That will check to make sure that the request was for a single entry and
that a post was set, then add a stylesheet to the stack for that
particular entry.

Note that this doesn't check to see if the stylesheet file exists. You
can get the filename of the css file with Site::get_path() and check
that before adding the stylesheet.

If your theme isn't configure like the core themes (as with most of my
own themes, it turns out), then this is a little more difficult. But
see if that works for you first.

Owen

ACME Media Farm

unread,
Aug 18, 2010, 11:38:59 AM8/18/10
to habari-users
Thanks Owen, I'm admittedly completely new to Habari - I've downloaded
it from time to time to check out the progress but tha's about it (I'm
a Textpattern/wordpress veteran). That being said can I bother you to
explain to me how to do the following:

> Note that this doesn't check to see if the stylesheet file exists. You
> can get the filename of the css file with Site::get_path() and check
> that before adding the stylesheet.

Thanks!

Owen Winkler

unread,
Aug 18, 2010, 1:30:43 PM8/18/10
to habari...@googlegroups.com
On 8/18/2010 11:38 AM, ACME Media Farm wrote:
> Thanks Owen, I'm admittedly completely new to Habari - I've downloaded
> it from time to time to check out the progress but tha's about it (I'm
> a Textpattern/wordpress veteran). That being said can I bother you to
> explain to me how to do the following:
>
>> Note that this doesn't check to see if the stylesheet file exists. You
>> can get the filename of the css file with Site::get_path() and check
>> that before adding the stylesheet.

Something like this:

<?php
if(
$request->display_entry
&& isset($post)
&& file_exists(Site::get_path(


'theme',
'/entry-' . $post->id . '.css'
)

) {


Stack::add('template_stylesheet',
array(
Site::get_url(
'theme',
'/entry-' . $post->id . '.css'
),
'screen'
)
);
}
?>

Owen

ACME Media Farm

unread,
Aug 18, 2010, 5:03:54 PM8/18/10
to habari-users
Great ! I'll give that a try - thanks for all of your help.
Reply all
Reply to author
Forward
0 new messages