Widget content as main content

I’m working on a Sage project that is using testimonials in a widget sidebar position and displaying on multiple pages in the main content through shortcodes.

I was hoping to be able to easily display all the widgets on one Testimonials page in the main content without having to just list all the shortcodes.

I was thinking I could create a template.php file and then create a copy of the base.php to base-testimonials.php and swap out the main content php with <?php dynamic_sidebar('sidebar-testimonials'); ?>

Doesn’t seem to work though and I’m also not sure if this would be the recommended way to do this even if it was working.

Of course, right after I post this I have another idea.

Would still like to know if this is an appropriate way to do this though.

I modified base.php as below:

<main class="main" role="main">
  <?php
    if(is_page('testimonials')){
      dynamic_sidebar('sidebar-testimonials');
  } else {
    include Wrapper\template_path();
  }
  ?>
</main>

That could work but isn’t exactly how I would do it…

  • I’d probably make a partial templates/testimonials.php and then put dynamic_sidebar('sidebar-testimonials'); in there.
  • Then I’d make a new page called page-testimonials.php and then I’d put get_template part('templates/testimonials'); there instead of the call to the content-page.php partial like so:
<?php while (have_posts()) : the_post(); ?>
  <?php get_template_part('templates/page', 'header'); ?>
  <?php get_template_part('templates/testimonials'); ?>
<?php endwhile; ?>

Boom. Now your base.php hasn’t been edited and you have everything split up all nice. Plus you can use the testimonials sidebar in other places now because it’s a partial!

2 Likes