Specify template for different queries
-
I have a question about how to use the templates for Query Wrangler that, if it’s not currently possible without a hack of some kind, will end up being a feature request.
Scenario:
I would like to employ the query templates to theme the look and function of the queries I’m creating. I might make a query called “Two Column Large Lead”, so the template’s file name in my theme would be “query-wrangler-two-column-large-lead.php”. For this query, I would want to filter my posts to only those matching the category of “Sports”. However, if I want to create another query, that uses a filter to show only posts matching the category of “Business”, the template it uses is based entirely upon the name I give the query. I would like to use the same template file for both queries, even though they are clearly different queries because they use different filters, and perhaps other differences in the configuration of the queries exist as well (post count, header/footer content, etc.). It’s possible for me to create two queries with the same name, and thus the same slug, so that they will both use the same template file, but if I do that, I have no way of knowing just by looking at the title of the query which is which. I would have to separately track the ID value of which query corresponds to which set of filters, in order to know which one I was using in widgets, pages, etc.Question:
Is it possible for me to have two different queries, with two different names, that can both use the same template? I could not accomplish this by using merely the “query-wrapper.php” generic template, because I have several combinations of queries that need to use the same template, i.e “Sports” and “Business” queries use one template, “News” and “Politics” queries use another.Current “Solution”:
The only way I can discern to make this work right now would be to get into the database and change the title of the query itself, but leave the slug as is. I believe this would effectively do the trick, but it doesn’t seem to be the best long term solution.Potential Solutions:
- If there is no other solution to this scenario using options that are already available in the plugin, it seems like one way to do this would be to add another option for the query that would allow the creator to choose from a list of available templates, that would be pulled from those automatically detected within the plugin’s default templates folder, as well as any that have been locally created in the theme directory.
- An additional option could be created for the query that would allow us to somehow categorize the query itself, and then automatically select a template that matched the name or ID of that category. In this solution, I might name the query “Business Articles”, and select a query category of “Two Column Large Lead”. The plugin would then look at the slug of the category and attempt to locate a corresponding template in my theme folder matching that slug, in the same way that it currently does using the slug of the query name.
If another solution to this scenario exists that I’m not seeing, I’d love to know what it is, but even if there is one, I propose that one or both of the solutions I suggested above could be a very useful addition to the plugin in a future version.
Thank you.
- The topic ‘Specify template for different queries’ is closed to new replies.