Only display certain categories

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Guest

Only display certain categories

Post by Guest »

I'd like to make it that only certain categories posts show up on the main site, and to restrict others to only show when the category is accessed from the menu. Is this possible through modifications or some sort of plugin?

Thanks.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Only display certain categories

Post by garvinhicking »

Yes, this can be done with a plugin solution.

But the easiest way is to set a fixed category for the mainpage to be displayed.

Edit your index.php and enter the line

$serendipity['GET']['category'] = '5';

Instead of 5 use the category id you want to be shown on the mainpage. Then your visitors must access the category list to view other categories.

As you can post to multiple categories, you can assign every entry for the mainpage category to (also) show up there.

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/
Guest

Not Working

Post by Guest »

Hi, thank you for such a quick reply. I've been trying to get this solution to work, but I'm having a hard time.

I'm not sure where this is supposed to be added/edited, so if you could clarify that I'd really appreciate it. I've tried editing a few lines that look similar and also adding the line you mentioned but simply modifying the category number to no avail.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Not Working

Post by garvinhicking »

I'd need to know which Serendipity version you're running? Then I can give you more detailed instructions...

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/
Guest

Versions

Post by Guest »

I'm using yesterdays CVS (s9y_200502061337.tar.gz) 0.8 development version. I suppose it'd be better to use the stable version though, right? I'm just used to the open source community treading very carefully with their versions, most development versions in my experience have been release quality, it just seems like developers are being careful. So far, this has been the case with the development snapshot (or so I've found, it's quite stable) as well. Kudos to you on that.

However, If it'll work better on a previous release, please direct me to which would be best.

Thanks, your help is much appreciated.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Versions

Post by garvinhicking »

Hi!

In fact you're doing the right thing - latest CVS is always better for us to tell you about. :-)

Now, just open your index.php file of Serendipity. Go to line 293. There you should see this line:

Code: Select all

    if ($serendipity['GET']['action'] == 'search') {
        $serendipity['uriArguments'] = array(PATH_SEARCH, urlencode($serendipity['GET']['searchTerm']));
    } else {
        $serendipity['uriArguments'][] = PATH_ARCHIVES;
    }

    include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
change that to:

Code: Select all

    if ($serendipity['GET']['action'] == 'search') {
        $serendipity['uriArguments'] = array(PATH_SEARCH, urlencode($serendipity['GET']['searchTerm']));
    } else {
        $serendipity['uriArguments'][] = PATH_ARCHIVES;
    }

    $serendipity['GET']['category'] = '2';
    include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php');
You see, I inserted the 'category = 2' line. 2 is the ID of my category (I can see that by hovering over the category sidebar list and look at the URL - first digit before the "-" is always the categoryid.

Try that :)

Have fun,
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/
Guest

Working Now

Post by Guest »

Wonderful, thank you very much for your help, it's quite appreciated! The modification is working fine, now I can get down to redesigning my journal.

Thanks again, Keep up the good work!
~chris
borzwazie

.7-beta 3

Post by borzwazie »

Can you also do this with the .7 version? I can't find the line you mention anywhere in the index.php at all.

thanks!
borzwazie

Re: .7-beta 3

Post by borzwazie »

borzwazie wrote:Can you also do this with the .7 version? I can't find the line you mention anywhere in the index.php at all.

thanks!
I did this in index.php:

Code: Select all

if (count($serendipity['GET']) == 2) {
        if (isset($matches) && is_array($matches) && isset($matches[1])) {
            $serendipity['GET']['category'] = $matches[1];
        }

        ob_start();
       $serendipity['GET']['category'] = '6'; 
        include_once(S9Y_INCLUDE_PATH . 'serendipity_genpage.inc.php');
which sortof works but now I can only view category 6. so close...[/code]
borzwazie

got it!

Post by borzwazie »

I did this:

Code: Select all

if (count($serendipity['GET']) == 2) {
        if (isset($matches) && is_array($matches) && isset($matches[1])) {
            $serendipity['GET']['category'] = $matches[1];
        } else {
            $serendipity['GET']['category'] = '6'; 
        }
        ob_start();
This seems to work!
Post Reply