Let’s take a look at an example situation: Let’s say you had a custom post type (though this code also works with normal WordPress posts) for resources and those resources were categorized. You’d typically make a Beaver Themer archive layout and a single post layout. Now, let’s say that you wanted to show a list of all the titles (or titles and their images etc.) in the same resource category on that single layout page. Currently you can’t do that because there’s no option in the ‘Posts’ module to limit it to only the current post’s category. We’re going to add that functionality and you won’t need to add another plugin to your install list to get the functionality. Here’s how it works:
On your Beaver Themer Single Post Layout build your design and add a ‘Posts’ module as usual. You can use any of the layouts or use the custom option and design it yourself. Make sure under the ‘Content’ tab that ‘Source’ is set to ‘Custom Query’ and in the ‘Advanced’ tab you add ‘all_posts_in_same_category’ as the class.
That’s almost it. All you have to do now is add this code to your ‘functions.php’ file. All this code does is tell Beaver Builder that when it renders a ‘Posts’ module if it has the class that we added in the last step to grab the current post’s type, taxonomy, and category and use that to get the list of posts. If it’s not there it will continue as normal.
Get In Touch