5

The site I'm working on has a couple of pages that needs to be filled with different content elements like text image combinations, sliders, lists of content, etc. The client would need to re-order these content blocks, add new ones and so forth. Every content block would be piece of content (post or custom post type) or a list of content.

From what I understand I have 2 options:

  1. Use an complex plugin to drag and drop predefined content
  2. Use shortcodes

From a developing standpoint I would rather not leave all the logic to a third party plugin. It seems I would lose some of the control over the templating?

But shortcodes don't seem like an acceptable solution for any customer, really, because they are too technical.

Any suggestions? Is there a best practice?

  • I know you said you wanted to avoid "using a complex plugin" but chances are you are going to have a need for custom fields at some point in the development process. ACF is easily one of the best plugins for this, will save you hours of dev time and has something called a "flexible content field" that might work for your needs without a complex layout/page builder plugin. Check it out: advancedcustomfields.com/add-ons/flexible-content-field – brianjohnhanna Jul 12 '16 at 20:26
1

This is an interesting question, though a bit too broad for a Q&A model. Here is what I would do:

  1. Create a custom post type, where each post is a block of content
  2. Create a second custom post type for pages that are assembled from blocks of code. In stead of a content field, create ten drop down fields (or more if there are more blocks possible on a page). For the select options in the dropdown, take the title of all posts in the first custom post type. In this way any new block of content will automatically become available for assembly.
  3. Create a template for the second post type, that loops through all drop down fields and assembles the content from the first custom posts.
  • Your approach should work but I can see some drawbacks: reordering content blocks would be painful and finding the right content by title could be difficult. Also, finding the right piece of content to edit could be confusing as this is a parent-child relationship, correct? Would it be difficult to filter posts by page in the backend? If there were 10 pages with 10 content blocks each, the customer would need an option to identify what content is being used on which page. I know that wordpress is not a CMS in the true sense, but you'd think more people would have this problem? – sven Jul 6 '16 at 11:58
  • 1
    Your concerns are valid, but they were not in the original post. Which is why I said the question is too broad for WPSE's format. Everybody with this kind of question will have his own concerns.. – cjbj Jul 6 '16 at 12:20
  • Agree the question is too broad. We also don't know exactly how and where the client is thought competent to interact with the back end - at what point "things getting technical" is too technical for our poor techno-peasant client... Is this a one-time operation or a several-times operation or an operation the client is going to perform continually? Maybe adding buttons to the Visual Editor would do the trick best, whether for a CPT or "regular" post/page... Who knows and who can say? – CK MacLeod Jul 12 '16 at 19:29
1

While shortcodes by themselves are linked to functions, I think you could use them effectively in combination with templates and a metabox for their input data. eg:

add_shortcode('content-box','content_box_function');
function content_box_function() {
    global $post;
    $title = get_post_meta($post->ID,'_content_box_title',true);
    $content = get_post_meta($post->ID,'_content_box_content',true);
    get_template_part('templates/content','box');
}

/wp-content/themes/theme-slug/templates/content-box.php

<div class="content-box-container">
    <div class="content-box">
         <h3 class="content-box-title"><?php echo $title; ?></h3>
         <div class="content-box-content"><?php echo $content; ?></div>
    </div>
</div>

Then add a metabox to the post writing screen to allow the user to select/define the meta values to go with the keys you are using for each content block shortcode.

Gives you the advantage of allowing the shortcode to be ordered/placed anywhere in the content, and still have other content there as needed be, but the templating (and related styling) could be worked out already for the predefined content block types.

1

You could consider using the page templates. For the example im going to use a contact page. "contact-page.php"

You can then write in the code you need for the template. To keep the flexibility look up how to use the Customizer (if you're not familiar with it) and use this in the template page to let the admin modify the page content without having to look at the code. This is how I've done my templates.

0

I evaluated the different options and went with a plugin "Page Builder". While the technical aspects are not great (e.g. data persisting: all content gets serialized) is was the only option to give me enough flexibility and enough comfort so that the customer could make changes to the structure of each page.

Migrating from dev to stage to live was also a pain due to the serializing and only possible with yet another plugin (duplicator).

Thanks everyone for the input!

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.