Page 1 of 1

CGBlog - Possible to search combinations of categories?

Posted: Sat Mar 29, 2014 8:06 pm
by WeeJimmyHat
I'm using CGBlog to add a database of projects to a website. Each project belongs to multiple CGBlog categories.

I'd like users to be able to search combinations of CGBlog categories to find what they're looking for, but I don't know where to start...

Generating a jump menu (or list of hyperlinks) with a single list of CGBlog categories is straightforward:

Category 1
Category 2
Category 3
Category 4
Category 5
Category 6


If a user clicks Category 1 all items in that single category are displayed.

But I'd like to display a list of checkboxes, or checkbox groups like this:

Category A1
Category A2
Category A3

Category B1
Category B2
Category B3

SEARCH >


Checking A1 + B1 would display all CGBlog items categorised as A1 and B1.

Anyone out there know where to start with this? I'd really appreciate any advice!

Re: CGBlog - Possible to search combinations of categories?

Posted: Sat Mar 29, 2014 9:06 pm
by calguy1000
CGBlog accepts a comma separated list of category names, and then will find all of the articles that match one of those categories. so

{CGBlog category='category a,category b'} will find all of the articles in category A or B.

so all you need to do is create a comma separated list of category names.

Something like this should work:

Code: Select all

<form>
<input type="checkbox" name="foo[]" value="category a">
<input type="checkbox" name="foo[]" value="category b">
<input type="checkbox" name="foo[]" value="category c">
<input type="checkbox" name="foo[]" value="category d">
<input type="checkbox" name="foo[]" value="category e">
<input type="submit" value="Filter"/>
</form>

{$category=''}
{if isset($smarty.post.foo)}
  {$category=implode(',',$smarty.post.foo)}
{/if}
{CGBlog category=$category}

Re: CGBlog - Possible to search combinations of categories?

Posted: Sun Mar 30, 2014 11:42 am
by WeeJimmyHat
Thanks so much for the quick reply, it's really appreciated. Unfortunately I can't get this to work though...

The filter generates a url like this:

Code: Select all

.../?foo%5B%5D=category+a
It does seem to be stringing together multiple categories as expected:

Code: Select all

.../?foo%5B%5D=category+a&foo%5B%5D=category+b
But I'm sure the url isn't supposed to look like this, and all entries are still shown.

I know I'm supposed to replace

Code: Select all

foo[]
with something else, but what? I've tried all sorts of things, including website section names, to no avail.

Category pages generated using {CGBlog action="browsecat"} have urls like

Code: Select all

.../cgblog/category/21/21/category-a/
(I'm using pretty urls).

Any idea what I'm doing wrong?

Re: CGBlog - Possible to search combinations of categories?

Posted: Sun Mar 30, 2014 12:20 pm
by Jo Morg
WeeJimmyHat wrote:I know I'm supposed to replace
Code:
foo[]
with something else, but what? I've tried all sorts of things, including website section names, to no avail.
I would start to replace each value="category a" by valid category names, and test it. The foo[] can be left as is just for testing purposes, but to modify it you'd have to:
  • - keep the [] at the end;
  • - avoid using category[] as category is already being used by the module itself (actually you would have to find a key that isn't going to collide with other keys already being used, so foo was a safe bet for testing purposes...);
  • - change all occurrences of $smarty.post.foo to $smarty.post.<whatever_name_you_gave>;
HTH