Filtering posts on the listing page after applying a custom choice object


I'm trying to set up a portfolio page by re-writing the blog post and listing page fuctionality using the methods described here

The only thing i've done differently is added a "choice" custom field because I saw this as a way for the user to define the type of post they were creating (whether for residential or commercial customers) - and so the values of the "choice" string are the aforementioned.

Now id like to filter the results between those two options on the listing page, in either a tabber or dropdown selector.

Is a choice or boolean field the best way to devise a "post type" here? How would i create filtering on the listing page? The above article suggests they would write how to do exactly that, but i dont think they got around to it.

Thank you for any help you may have to offer
1 Reply 1
Contributor | Gold Partner

I'm not sure about your JS skills, but I made something similar for one of my blogs. This solution is filtering posts by topic however.


The filter function is using js and hides all posts that do not contain the chosen topics.

<script type="text/javascript">
    var cases = $('.post-item');

function updateContentVisibility() {
  var checked = $("#filterControls :checkbox:checked");
  if (checked.length) {
    var checked = $('#filterControls :checkbox:checked');
    $(,a){return '.'+a.value;}).splice(0).join('')).show()
  } else {;

$("#filterControls :checkbox").click(updateContentVisibility);

Then there is the actual list of topics that you can filter by, which is generated as a list of checkboxes, using this HubL code.

{% set blog_topics = contents_topics %}
<div id="filterControls">
    {% for blog_topic in blog_topics %}
<input type="checkbox" value="{{ blog_topic.slug }}" />{{ blog_topic }}
</label> {% endfor %} </div>

If you only need to filter between two different types of posts you can probably make it even simpler. Let me know if this was helpful whatsoever.