$selectedCategory and Pagination conflict?

17 posts by 6 authors in: Forums > CMS Builder
Last Post: June 21, 2010   (RSS)

By Perchpole - March 3, 2010

Hello, All -

I'm working on a framework for a client and have noticed an apparent conflict between the $selectedCategory rule and page pagination.

In order to define which items are shown in a list, you must first define the parent category. This is often achieved by of getNumberFromEndOfUrl(); - which I believe defines the value of $selectedCategory.

For example: http://www.mysite.com/?cat=1

In the example above, a value of 1 is returned - so the $selectedCategory would be 1.

However, if you use a pagination link to move to the next page, it appears to break the relationship.

Example: http://www.mysite.com/?cat=1&page=2

Here getNumberFromEndOfUrl(); returns a value of 2 - which means the $selectedCategory is also 2.

I assume I've got this right? If so, how can we work around it?

:0(

Perch

Re: [Perchpole] $selectedCategory and Pagination conflict?

By flamerz - March 3, 2010

add this in the list of $selectedCategory (after the tableName line):

'selectedCategoryNum' => @$_REQUEST['cat'],

i think it will work.

Re: [flamerz] $selectedCategory and Pagination conflict?

By Perchpole - March 8, 2010

Hi, Flamerz -

Thanks for your advice. Sorry for not responding sooner.

Despite yopur suggestion I still cannot unravel the problem. I think it might be easier to explain by taking a quick look att his example...

http://www.perchpolemedia.com/demo/category_test/testList.php

The menu at the top of the page lists the 4 available categories. The number in brackets denotes the category number.

Beneath this is the list of articles pulled from the database. (NB: In this demo the page is set-up to show just one article per page.)

Near the bottom - just above the prev/next links - you will see the record and category numbers. The latter should correspond to the selected menu item. "Reviews", for example, is category 4.

If you click on any of the menu links the resulting article will have a category number matching that of the selected menu item.

However, if you go back to the start - by clicking on the All Articles link - and then use the prev/next links, things are a bit more unpredictable!

If you click on the "next" link, page 2 will appear. The article shown is actually a "Review", from category 4, but the item hi-lighted in the menu is "Articles" - which is category 2.

If you proceed to the next page (3) "Guides" is hi-lighted in the menu - which just so happens to be category 3.

And so on...

In other words, when using the prev/next links, the category number is determined by the page number.

I can't quite work out what's going wrong?

:0(

Perch

Re: [flamerz] $selectedCategory and Pagination conflict?

By Perchpole - March 8, 2010

Hi, Flamerz -

Sorry. I should have made it clear in my earlier post that I'd tried your suggestion and it doesn't appear to work. It's active on the demo right now...

http://www.perchpolemedia.com/demo/category_test/testList.php

It doesn't appear to change anything.

:0(

Perch

Re: [Perchpole] $selectedCategory and Pagination conflict?

By flamerz - March 8, 2010

can you post the php code?

i had the same issue than you, but solved with that line.

[:/]

Re: [flamerz] $selectedCategory and Pagination conflict?

By Perchpole - March 8, 2010

Hi, Flamerz -

No problem. File attached.

Thanks for your help.

Perch
Attachments:

testlist.php 4K

Re: [Perchpole] $selectedCategory and Pagination conflict?

By Dave - March 8, 2010

Hi Perch,

I think the problem is related to the fact that if 'selectedCategoryNum' doesn't contain a number greater than 0 then it defaults to getNumberFromEndOfUrl().

So you might need to write some special code to allow for the "All Categories" menu option. One quick-fix would be to add &lastNum=0 to the end of the page links:

testList.php?page=2&lastNum=0

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] $selectedCategory and Pagination conflict?

By Perchpole - March 8, 2010

Hi, Dave -

Thanks for your input. I'm not entirely sure how lastNum works (perhaps you can provide more info) but I'm happy to experiment.

Having said that, it occurs to me that in order to navigate a category framework without problems, you need to include "category=x" somewhere in the link structure. Without it, the system seems to get lost.

In that case, shouldn't every category framework extend from a single, parent category? That way there's always something you can use as a point of reference.

In effect, the "All Articles" link above should be "category=0" a default, master category which would list the contents of the 4 sub-cats.

At least this way the pagination wouldn't trip up in instances similar to those in my own example.

:0/

Perch

Re: [Perchpole] $selectedCategory and Pagination conflict?

By Perchpole - March 9, 2010

Hello, All -

I've been playing around with this issue and it appears to raise a number of interesting problems. Perhaps the most obvious concerns searches.

If you return to the demo page...

http://www.perchpolemedia.com/demo/category_test/testList.php

...you'll see that I've added a rudimentary search function to the foot of the page. It's configured to search article titles.

Try searching for the word "the".

The search will return 3 results. The first of these will be shown on the default page.

If you click "next" to view the second result, however, we start having problems. As there is no category defined, the $selectedCategory defaults to the number from the end of the URL - in this case page=2. As a result, the page now "thinks" it's being instructed to re-load as a category 2 page - hence the hi-lighted "Articles" link in the menu.

I appreciate what Dave was saying about modifying links but surely this issue is worthy of a more comprehensive solution?

Either we need to identify a best-practice approach to using categories or come up with some sort of "catch-all" code that will handle situations when no category is identified in a link.

:0s

Perch