Help with setting Default Category

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
shicks
Regular
Posts: 5
Joined: Tue Feb 14, 2006 10:43 am
Contact:

Help with setting Default Category

Post 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
Last edited by shicks on Tue Feb 14, 2006 11:27 am, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Help with setting Default Category

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
shicks
Regular
Posts: 5
Joined: Tue Feb 14, 2006 10:43 am
Contact:

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply