0

I'm looking for a way to have a post template that has two sidebars, one on the right side, the other on the left side, with always the same content on each one of them.

I defined that left sidebar as "sidebaraleatorio", and right sidebar as "sidebarrecomenda", and created for each one of them a .php file, then I registered them in my functions.php of child theme. After that, I created a template trying to call the two sidebars php files:

<?php get_sidebaraleatorio(); ?> <?php get_sidebarrecomenda(); ?>

But when I tested, there were several bugs, so I guess something is wrong in my way of doing it... Shouldn't I create different sidebar php files?

If the problem is not that, I can include the other code I'm using on these files

Thanks a lot for any help

2

If you add sidebar-sidebaraleatorio.php and sidebar-sidebarrecomenda.php sidebar templates to your (child) theme directory, you can then call them with get_sidebar() function.

Like so get_sidebar('sidebaraleatorio); and get_sidebar('sidebarrecomenda);.

You can read more about sidebars from the Developer Handbook > Sidebars.

7
  • Thanks Antti. Just to clarify, I should add this get_sidebar function to the template file I am creating? Besides that, I still need to registered them in my functions.php, right?
    – usina
    May 22 '19 at 19:06
  • @usina Yes, you can use get_sidebar in your template files. If you want to have dynamic sidebars / widget areas in your sidebars, then you should register sidebars in your functions file, too. I think get_sidebar() only includes the sidebar template file, so it can have either static and/or dynamic content. May 22 '19 at 19:17
  • Hi Antti. Thanks, this procedure is indeed working. But another related question. If I want to have an extra sidebar, besides the one that comes with my theme, should I use get_sidebar in my sidebar.php file as well as creating a new one? What I did was 1. Create a new secondary-sidebar.php 2. Register it in functions.php 3. Add a widget to it via WP frontend 4. Call it via get_sidebar in index.php. But it did not work. Am I doing something wrong? Thank you
    – usina
    Jun 1 '19 at 4:57
  • @usina You need to add the get_sidebar() function for your custom sidebar to every page template where you want to display it. E.g. singular / single / page / archive.php, unless index.php is the only template file you have in your theme. Jun 1 '19 at 10:34
  • I am trying to add it to a single post, so in single.php, after <?php get_sidebar(); ?> I added another line <?php get_sidebar( 'secondary' ); ?>. Instead of pulling the sidebar, when I opened the post it returned an error of layout saying that website is under technical difficulties. Should I substitute or just add another line for this new sidebar in index, single and other places as well?
    – usina
    Jun 1 '19 at 13:38

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.