1

On my website I've two category pages, one called "agenda" and the other "artículos". I've set theme on the main menu:

https://institutoschuman.org/

I'd like to have different sidebar for each one of this category pages. Unfortunately my theme doesn't let me to do this. Is there a way to do that without installing many plugins? Or, is there only one plugin that let me to do that?

Thank you for your help

2

one way to accomplish your goal would be to create a child theme (https://codex.wordpress.org/Child_Themes). You create a folder inside /wp-content/themes/, then add a style.css file inside it with a few comment lines at the top to tell WordPress this is a child theme of whatever your current theme is.

Sample style.css file: all you need to do is change parent-theme-folder-name to whatever your original theme folder is. So for example if you are currently using Twenty Sixteen, change parent-theme-folder-name below to twenty-sixteen.

/*
Theme Name: Custom category sidebars
Version: 1.0
Template: parent-theme-folder-name
*/

Next, to create your new sidebars, create a blank functions.php inside your child theme folder, and add:

<?php
/**
 * Add custom sidebars for categories
 */

// Agenda Category Sidebar
register_sidebar(array(
    'name'          => 'Agenda sidebar',
    'id'            => 'agenda-sidebar',
    'description'   => 'Agenda category sidebar'
));

// Articulos Category Sidebar
register_sidebar(array(
    'name'          => 'Articulos sidebar',
    'id'            => 'articulos-sidebar',
    'description'   => 'Articulos category sidebar'
));

Finally, create a blank category-agenda.php file and a blank category-articulos.php file. Copy and paste your original theme's category.php code right into those files. Then, look for the sidebar portion, and change the part where it calls the sidebar:

Again in this example just change sidebar-slug to your new slug: in category-agenda.php change it to agenda-sidebar, and in category-articulos.php change it to articulos-sidebar.

Once all these files are created and uploaded, activate your child theme and set up the widgets in the sidebars however you like.

  • It should be noted that the Template: value in the style.css file of a child theme should match the folder name of the parent theme. – Mat May 18 '18 at 18:50

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.