1

I'm developing a custom single-page site & theme for a client, I'm currently using pages & child-pages (post-type:page) to make the sections of the site laid out like so

Heading "Page"
Image "Page"
⌙ image 1
⌙ image 2
⌙ image 3
Contact "Page" (gravity forms)
Sponsor "Page"
⌙ sponsor 1
⌙ sponsor 2
⌙ sponsor 3

(where denotes a subpage)

is this there a better way to manage multiple segments of content that will appear on the same page?

  • 1
    This will work but I prefer creating a Theme Options section that allows the user to select which page to use for each section. This only works if there are a set number of sections on the page though. – Fencer04 Jul 19 '16 at 0:11
  • 1
    Another approach is to use the drag/drop in the core nav-menu-builder, (here's an example), to create a list of items of any type. – birgire Jul 19 '16 at 13:22
2

I would not recommend using subpages for sections for the following reasons:

  • The section subpages can be deleted, set to draft and many other misuses by mistake.
  • It is difficult to control the user input on them.
  • There is no easy way to deal with booleans or options, such as "show/hide this" or "use design 2 for this section".
  • When retrieving the page content, there might interferences with plugins altering the_content hook.
  • It is not easy to extend this method to other pages in the same website without messing up the admin's pages list view with countless subpages.

For the task of building up a section based page, there are so many different methods in the end there is probably not a single correct answer that can cover all the possible cases.

I have had to work with many different solutions for this task, such as:

  • A widgetized homepage sidebar with custom made widgets.
  • A "Sections" custom post type with support for page-attributes to allow custom ordering.
  • Shortcodes for opening and closing sections.
  • A separated options page.
  • Content builders.
  • ...

But in my experience what turned out to work better in production in those cases where the user is not intended to design but to fill in content were metaboxes, which happenend to be the native tool WordPress provides for custom content in pages. The users find them more intuitive than the content builders and their manipulation is much less error prone than any of the others solutions.

The usage is simple: add one or as many metaboxes as sections you need. Then, in each one, declare as many fields as editable content there will be in that particular section. And finally modify the frontpage.php of the theme or create a custom template that reads and prints those metaboxes contents. Remember to escape them.

If you need some dynamism in your metaboxes, such as reordering, repeater fields, wysiwyg editors, etcetera, have a look at CMB2, a free, mature open source library that allows you to use several fields in a very easy way. You can also opt for Advanced Custom Fields, a plugin with a very extense free functionality and some premium features that differs from CMB2 in offering a fully working frontend.

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.