CGBlog - Possible to search combinations of categories?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
WeeJimmyHat
Forum Members
Forum Members
Posts: 18
Joined: Fri Feb 18, 2011 10:17 pm

CGBlog - Possible to search combinations of categories?

Post 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!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CGBlog - Possible to search combinations of categories?

Post 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}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
WeeJimmyHat
Forum Members
Forum Members
Posts: 18
Joined: Fri Feb 18, 2011 10:17 pm

Re: CGBlog - Possible to search combinations of categories?

Post 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?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1942
Joined: Mon Jan 29, 2007 4:47 pm

Re: CGBlog - Possible to search combinations of categories?

Post 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
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Modules/Add-Ons”