You know how sometimes you work on a project and can’t figure out how to do something, so you give up on it for a while and then two months later, inspiration hits and you suddenly realize exactly how to accomplish it?
Well, that happened to me. For this project, I needed blog pages to pull lists of posts for categories (so, that’s easy to do because of this nifty Genesis Framework tip), but also to pull lists of custom post types. The kicker was that I didn’t want just the standard blog loop on everything–for some I wanted a page that worked more like a portfolio page, for example, just showing a grid of featured images with titles, and on at least one page, I wanted something more like a Pinterest style grid (which is a whole other post). I could accomplish exactly what I wanted by building my $args directly into my template file, but that locked it down so that it could only be used for one custom post type or category, not really a template after all. I really wanted to be able to use the query_args custom field that I use with the regular Genesis blog template but couldn’t see why it wouldn’t “take” when I tried it.
* Disclaimer: really smart developers frown on using the query_args, period, as I understand, but what I really like about it is that I can use and reuse one template file for several different loops, all from the front end, and what I’m doing is something I can also teach my clients to do, which is one of the reasons I love using WordPress in the first place. *
You May Also Like:
Until I looked deeper into the Genesis files themselves! Turns out that it’s not a WordPress thing, I guess, or at least it’s something built into the Genesis Framework. Once I put that into the template page, I was able to add a query_args custom field and pull whatever I needed.
It’s actually so very easy that I set it up on my own website after I wrote this post, so I could have an image to show you. If you click the image, you’ll go to my web design portfolio page and see this template in action (since the project I’m working on hasn’t been released yet).
The Blog Template File
Here’s my blog_featuredimage.php file–call it whatever makes sense to you, and change the div names as well, if you like.
Change the styling to match what you did for your divs above–obviously you can be as creative as you like with the styling.
The query_args Custom Field
Here’s an example of the query_args I used:
This custom field called pages instead of posts, children of the page I used as my blog template, put them in a random order, and shows all of them (instead of splitting them into multiple pages if there are more than what’s set to show on one blog page). You can use it with a custom post type, a category (as mentioned in my previous post), whatever you like.
This was actually surprisingly easy to implement–I was quite pleased.