CMS Development

Woodsy
Top Contributor

Create a blog filter for resource type

How can I create a filter for resource type that can be used as well as the topic filter? I have set up a custom field in my blog post that captures the resource type:
{% choice "resource_type" label='Choose the resource type', value='type', choices='eBook, Case Study, Infographic, Technical, Video, White Paper', export_to_template_context=True %}

 

How do I use this info to be able to filter the blog posts in a dropdown?
This is what I am currently using for the topic filter:
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Filter resources by &#x25BC;</button>
<div id="myDropdown" class="dropdown-content">
{% post_filter "posts_by_topic" select_blog='5124593000', expand_link_text='see all', overrideable=False, filter_type='topic', label='Posts by Topic' %}
</div>
</div>

 

Can I write something similar for the resource type?

0 Upvotes
2 Replies 2
Anonymous
Not applicable

Create a blog filter for resource type

Hi @Woodsy,

were you looking for functionality like this in a dropdown?

http://psdtohubspot-2432204.hs-sites.com/filter-blog

For adding a filter like this, you have to use some scripting to display the posts with the active topic and hide the remaining. You can trigger update view when a topic is selected and show the specific posts. If you have any queries re this, please let me know.

0 Upvotes
Jsum
Key Advisor

Create a blog filter for resource type

@Woodsy,

 

Yes you can.

 

To create the drop down you can either hard code the list or use the for contents loop to ouput a link for each unique resource type.

 

You probably want to have the list with anchor tags instea of a select field. the href for your links can be www.website.com/blog?q=resource-type

 

Then you can use and if statement to check for a query in the url. If the query exists compare it to the resource type field, in a new for contents loop, for each post using an inner if statement. 

 

This is very similar to this answer I shared with your before but instead of setting the query using a search box you are linking directly to it with you drop down links. Also, instead of checking for the query in several fields you are only going to check your resource type field. 

 

It's going to take some extra logic on your part to have both your topic and resource type drop down working at the same time, just so you know. Get the basic set up done and you should be able to figure it out.

0 Upvotes