Page 1 of 1

Help with setting Default Category

Posted: Tue Feb 14, 2006 10:54 am
by shicks
I installed serendipity 1.0-beta1 and added 2 categories. I would like to default to showing only entries of the 1st category if none are selected (i.e. when first arriving at the blog).

I tried adding the following to index.php:

Code: Select all

if ( !( preg_match(PAT_PERMALINK_CATEGORIES, $uri)
         || (isset($serendipity['POST']['isMultiCat']) && is_array($serendipity['POST']['multiCat'])))
    ) {
   $serendipity['POST']['multiCat'] = array(1);
   $serendipity['POST']['isMultiCat'] = true; 
}
The entries are displayed correctly but the CSS file no longer is retreived. I cannot figure out why!

I then restored index.php and created an event plugin : default_category with a hook to frontend_configure with this code:

Code: Select all

                    if (! preg_match(PAT_PERMALINK_CATEGORIES, $_SERVER['REQUEST_URI'])) {
                        $serendipity['POST']['multiCat'] = array(1);
                        $serendipity['POST']['isMultiCat'] = true; 
                    }
The entries of the first category are displayed correctly but the CSS doesn't work any more.

Any ideas? I've searched this forum and have been fooling with it for hours. Hopefully is just something simple?

Thanks

Re: Help with setting Default Category

Posted: Tue Feb 14, 2006 11:26 am
by garvinhicking
There already is a plugin for that, which should work pretty well:

Serendipity_event_startcat, which can be found here:

http://cvs.sourceforge.net/viewcvs.py/p ... _startcat/

(or via spartacus)

HTH,
Garvin

Posted: Tue Feb 14, 2006 11:54 am
by shicks
Thanks for the quick reply.

I had tried using that plugin but it sets the ['GET']['category']. The problem with ['GET]['category'] is the title is not set to the category name since that block of code in index.php is not reached.

I had tried to emulate the serendipity_categories_plugin which causes a POST or PATTERN match to reach the block of code in index.php which deals with multicats.

It still seems like my code should work. It does, but the CSS gets messed up. Weird.

THanks

Posted: Tue Feb 14, 2006 12:04 pm
by garvinhicking
Are you sure about the code in index.php not being reched? The plugin uses frontend_configure as the hook, which is executed BEFORE the index.php preg-call block. It should basically work.

If not, the plugin could set the blogTitle etc. on its own, of course. So you could modify that easily.

Your CSS is likely to get borked because the serendipity.css.php might not parse your code well and choke on it. What's your URL?

Regards,
Garvin