0

I am using a custom post type (CPT) trainings on one of my client's sites. I've also added a CPT called sidebars, which can get linked into trainings or pages via the "relation" field type. To get an overview over all trainings, I've created a separate template "tpl-trainings.php" and added an "overview"-page, which in turn uses the template. That way, the client can add sidebars (e.g. for general contact information) and use the sidebar on different other pages, including the trainings overview page.

However, there's an issue. Since the trainings-CPT has the url /trainings/..., I cannot add a page with the permalink /trainings/, but have to cheat and use /training/. This is inconsistent and not what wordpress intended with the hierarchy. If I add an archive-trainings.php, the archive page is obviously loaded correctly, but the client is unable to link the sidebars he needs, because the archive page does not have an own menu entry in the backend.

Does anyone have an idea on how to solve this, besides adding custom code to the themes backend menu options?

1

In this situation I would use the page as a placeholder to configure the sidebars, even though WordPress will completely ignore it on the front end.

Just add the page, make sure the slug is trainings, let the client set it up as they need, and then in your template:

if ( $trainings_page = get_page_by_path( 'trainings' ) ) {
    $acf_sidebars_data = get_field( 'sidebars_acf_field_name', $trainings_page->ID );

    // Carry on sergeant
}
  • That's a nice solution - not completely clean, but better than putting it into the theme's menu. Thanks! – Lars Aug 27 '15 at 9:37

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.