Page 1 of 1

write category to URL?

Posted: Thu Oct 12, 2006 4:45 am
by tropfstein
Hi all,

I'd like to setup the following scenario:
I installed an embeded blog in an existing site and I want to split it up into two sections.
With the "Start Page Category" plugin I set my initial view category to cat1 and I hide cat2, which works perfectly.

I access my second section by a hardcoded link directly to blog/categories/2-cat2.
cat2 uses a different template and it works excellent so far.

Now comes the problem: I have my navigation links in a smarty-template file called navigation.tpl. Every site passes a variable to that file which contains if-statements like {if $nav=="xy"} class="active"{/if}. This is for highlighting the corresponding navigation link.

If I define $nav=cat1; in my index.php of serendipity and then choose my second blog section it shows up the correcht section but it highlights still the link cat1 instead of cat2.

I did some stuff like:
if (strstr($_SERVER['REQUEST_URI'],'/cat2/') OR $_SERVER['REQUEST_URI'] == "/blog/categories/2-cat2")
{$nav="cat2";}
else
{$nav="cat1";}

that works so far, but when I open a single entry the url is like 12-titlehere.html. I don't have chance to "read" the correct category from the url now.

Now I installed the "Custom Permalinks for Entries" plugin and gave all the cat2 entries a link like /blog/cat2/12-titlehere.html. cat2 is in my url now and I am able to determine which link has to be highlighted, but now occurs another problem: serendipity doesn't brings up the assigned skin but it brings up the default one for cat1. It seems that serendipity can't determine the category when the permalink-plugin is in use.
This two plugins seems to be incompatible.

I have two ideas how to solve my problem:

a) have the permalink-plugin disabled but rewrite the url of an entry to contain it's category name. Unfortunatly I just have %id%, %realname%, %username%, %email% as options and I would need something like %category%

b) use the permalink-plugin and make it compatible with the "theme-assign" plugin.

Has anybody a solution for my problem?

I hope my post isn't too complicated :)

I look forward to a response and thank you in advance!

Best regards,
tropfstein

Re: write category to URL?

Posted: Thu Oct 12, 2006 10:19 am
by garvinhicking
Hi!

Actually whenever you're in a category, you should be able to check in $serendipity['GET']['category'], which will be set in the serendipity core even in single article view. It should be available in Smarty scope as {$category_info.categoryid} and {$category}.

HTH,
Garvin

Posted: Thu Oct 12, 2006 12:08 pm
by tropfstein
Hi Garvin,

thank you so much for your reply.
I have cat1 as my initial start category and I hide cat2.

There is probably a bug somewhere, then in the single post view every post has $serendipity['GET']['category'] == 1, although the post is assigned to the categoryid 2.

Do you have any idea about that?

Posted: Thu Oct 12, 2006 12:15 pm
by garvinhicking
Hi!

Which version of the startcat plugin are you using? The most recent one? I remember that a patch was made to the plugin for cases like this.

You are right though, the startcat plugin heavily modifies those variables, which I sadly forgot.

HTH,
Garvin

Posted: Thu Oct 12, 2006 1:12 pm
by tropfstein
Hi Garvin,

you are rocketfast :)

I use the newest version 1.5. Just checked the cvs 1.9, its the one I have.

Do you have an idea how to "fix" that?

Another solution would be to form the url in a way which contains the categoryname, like blog/cat1/12-titlehere.html.

Is there a way to do this?

Thank you so much for your help!

Posted: Thu Oct 12, 2006 1:53 pm
by garvinhicking
Hi!

Sadly I don't have the time to introspect that right now. But the problem will most likely be within the startcat plugin, which sets $serendipity['GET']['category'] depending on some settings. There's also code that checks $serendipity['GET']['id'] for single entry view.

Then did you check you're using the most recent categorytemplates plugin? This one also sets 'category' depending on the 'GET''id' column.

Since you seem to be able to understand PHP, maybe you could have a look at those two plugins and try to isolate at what point the wrong category is set, or where setting the category-id to the id of the category of the single entry fails?

It might even be a problem of the order of event plugins. Try to put the categorytemplates plugin AFTER the startcat plugin?

HTH,
Garvin

Posted: Thu Oct 12, 2006 3:33 pm
by judebert
It seems to me that this problem is nearly unsolvable by design: an entry can have multiple categories, leaving us with some thorny questions to answer (in the general case). Which one should be chosen for the URL? Which one should be chosen for the template? How does the answer change if there is a specified template for more than one of the categories?

Posted: Thu Oct 12, 2006 3:48 pm
by garvinhicking
Hi Judebert!

I believe that tropfstein has this clearly seperated, so that his entries are always only in one single category. Of course you are right, were entries associated to multiple entries, the detection routine would need to only pick the first category, or use the default template...

Regards,
Garvin

Posted: Thu Oct 12, 2006 4:03 pm
by judebert
Agreed. And we may be able to solve his specific problem with Smarty, or with a code modification.

But I'm thinking of the general case. For other bloggers, those problems will have different answers.

You're right, though. It looks like he uses only single categories, and he seems to have some PHP knowledge, in which case modifying the single-entry code to include the category is likely the easiest option.

Posted: Thu Oct 12, 2006 4:04 pm
by tropfstein
garvinhicking wrote:I believe that tropfstein has this clearly seperated, so that his entries are always only in one single category.
exactly, I assign just one category. I'm looking up the code right now.. my skills aren't very good so it takes some time.. :)

Posted: Thu Oct 12, 2006 5:26 pm
by tropfstein
Well, it seems that I have to find another solution, my skills are not good enough to realy understand the code.
I tried some stuff but without success.

Thank you guys for your help anyway!

If I'll find a solution for my problem, I will post it here.

Posted: Thu Oct 12, 2006 5:53 pm
by garvinhicking
Hi tropfstein!

Don't give up so fast. :)

Did you try out my suggestion about moving the order of the plugins?

Regards,
Garvin

Posted: Fri Oct 13, 2006 9:43 am
by tropfstein
garvinhicking wrote:Hi tropfstein!

Don't give up so fast. :)

Did you try out my suggestion about moving the order of the plugins?

Regards,
Garvin
Yes, I tried that option, but it didn't help.

The problem lies somewhere in here:

blog/plugins/serendipity_event_startcat/serendipity_event_startcat.php, line 125

Code: Select all

$bc = $this->get_config('base_categories');
                    if (empty($bc)) {
                        $bc = $this->get_config('base_category');
                    }
                    if (!isset($serendipity['GET']['id']) && !empty($bc) && $bc != 'none' && $serendipity['GET']['category'] != 'all') {
                        $serendipity['GET']['category'] = $bc;
                        define('STARTCAT_CATEGORY', $bc);
                    }
$bc seems to be empty if a single entry is opened, so the following line

Code: Select all

$bc = $this->get_config('base_category');
gets in action.

Its probably just necessary to change this: $this->get_config('base_category');
But as I wrote, I don't see through it :roll:

Has someone an idea how to define the category id of the single post there?

Thank you for your help, guys!

Posted: Fri Oct 13, 2006 10:24 am
by garvinhicking
Hi!

I just tried to reproduce your problem. But it works perfectly here in this environment:

Serendipity 1.1-beta5
Startpage plugin 1.5
Category Templates 0.8

I'll mail you my URL where you can see this via PM.

Best regards,
Garvin