1

I'm looking to port a site into Wordpress that contains not just an About page, but an entire About section with various pages highlighting particular details about the company. Each of these pages vary in terms of layout and content but none are what could be described as being amendable to a custom post type. This is mainly because the site should only have one instance of each of these pages at any given time.

So I'm looking for some advice on how to handle pages like these. As far as I know the two options are custom templates and custom post types, but both seem to have drawbacks:

  • custom templates would allow the author to make pages and associate them to the appropriate template, but I'd like to add extra metaboxes for certain aspects of these pages. But it seems (correct me if I'm wrong) adding metaboxes to pages would apply them to all pages.
  • custom post types - I could define a custom post type for each 'type' of about page. This would give me my metabox flexibility but this seems like a 'heavy' approach. Also, not sure I could establish parent/child pages within a CTP?

Any advice on the best approach here? I'm leaning towards CTPs but would love to know of any best-practices for these types of pages.

Thanks in advance

0

"advice on the best approach" questions do not make for very good questions here as they tend to be pretty broad and subject to opinion, but I'll give you some options and hope for the best.

Option 1:

You should be able to use ordinary pages for this. Create templates for your custom content just as you are considering in your first option. Then you can conditionally add metaboxes based on those template choices.

function conditional_box_loader($post) {
  $template = (!empty($post->page_template)) ? $post->page_template : 'default';
  switch ($template) {
    case 'template-one.php' :
      // add metaboxes for this template
    break;
    case 'template-two.php' :
      // add metaboxes for this template
    break;
    default :
      // add fallback boxes, if required.
      add_meta_box(
        'read_only_content_box', // id, used as the html id att
        __( 'Post Content (Read Only)' ), // meta box title
        'read_only_cb', // callback function, spits out the content
        'page', // post type or page. This adds to posts only
        'advanced', // context, where on the screen
        'low' // priority, where should this go in the context
      );
  }
}
// callback I stole from another answer I wrote earlier today
function read_only_cb($post) {
  echo apply_filters('the_content',$post->post_content);
}

Option 2 :

You can do essentially the same thing with a CPT and a dedicated post type might prove to be more convenient.

Option 3 :

Instead of switching based on a template choice you could switch based on a post title, ID, or create a meta box with a "master" switch that would let you pick the meta box "set" that you want to enable.

  • Brilliant, didn't think to add metaboxes conditionally. Thanks for the tips! – wittyhandle Nov 29 '13 at 23:02
0

Actually, by using the Advanced Custom Fields plugin, you can add metaboxes to just a certain page template.

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.