1

I'm working on a news theme. I'd like most of the home page to be a basic loop but I want the top section to be user configurable.

For example, if there is breaking news, the user could choose an option that would only show one large story. But if it's a slow day, they can switch to 3 or 4 feature stories. This is similar to how the old version of theverge.com worked.

I'm thinking I could use various get_template_part()s to make the layouts but I don't know how to allow the user to choose which template from the admin.

0

If you're looking for a native WordPress solution I'd recommend using the Theme Customize API. It can be a bit overwhelming at first, but it's worth the investment in learning how to use it. Once you understand the concepts and have built your own Theme Options, you'll find it solves a lot of problems for you. In general, you could give the user a dropdown option for "Default Layout", "Large Story", and "Slow Featured", etc.

Using get_template_part is a great way to toggle your layout.

As for allowing the user to "pick" the Large Story (or "picking" the 3-4 featured stories), I'd recommend creating a Custom Taxonomy (similar to a tag) so the user can "tag" a story as a "Large Story" or "Slow Featured Story".

Then, in your "Large Story" template part, you can use WP_Query to fetch "posts with a term large-story, reverse chronological (newest), limit 1"...

And in your "Slow Day" template part you can use WP_Query to fetch "posts with a term slow-featured, reverse chronological (newest), limit 4"... etc.

1
  • 1
    For others looking to do what I did, here's my solution that works great. Add a custom setting to the theme via the Theme Customize API. I added radio buttons that allow the user to select a custom homepage layout. Add ifelse statements in index.php (I'm using Sage so it's a little more complex) that checks the stats of the new setting. Use this to change the display of the wp_query.
    – shrm03
    Jun 27 '17 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.