0

I can't seem to see a plugin for this, but it's functionality a client has asked for.

I want users to be able to customise the categories of posts that they can see. Let's say I have posts in the following categories:

  • Cars
  • Bikes
  • Trucks
  • Caravans

I want the user to select which categories they are interested in, ie. Cars and Bikes, and only show posts within those categories. So they can essentially filter the channel view.

2
0

You can chain category ids and pass them into the category="1|2|3" parameter. Docs here.

Use the exp:channel:categories tag to output a list of the categories with checkboxes, and use jQuery to grab the checked category ids and put them into a segment.

{exp:channel:categories channel="YOUR_CHANNEL" style="linear"}
    <p>
        <input type="checkbox" class="category" category-id="{category_id}" /> {category_name}
    </p>
{/exp:channel:categories}
<a onclick="filter();">Filter Entries</a>

The javascript function, replace with your template group and template

<script type="text/javascript">
function filter(){
    var categories = new Array();
    $(".category:checked").each(function(){
        categories.push($(this).attr('category-id'));
    });
    categories = categories.join("|");
    window.location = "{path='TEMPLATE_GROUP/TEMPLATE'}/" + categories;
}
</script>

And then in your exp:channel:entries tag.

{exp:channel:entries channel="YOUR_CHANNEL" category="{segment_3}"}
    ...
{/exp:channel:entries}
1
  • This is a cool idea, but will it persist? I would want to store the user selection in the DB so they can save their preferences. – tigercore Oct 13 '15 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.