Hi @sublimeandcolour!
To display a widget, we’ll need to create a new sidebar to hold the widget.
First – set up a child theme.
We’ll start by creating a new sidebar by adding the following to the functions.php
of the child theme:
register_sidebar( array(
'name' => esc_html__( 'Left Sidebar', 'orvis' ),
'id' => 'sidebar-2',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
That tells WordPress that there should be a second sidebar. Next we’ll tell it how to build that sidebar.
In your child theme folder, create a new file named sidebar-left-sidebar.php
.
Paste the following into that file:
<?php
if ( ! is_active_sidebar( 'sidebar-2' ) ) {
return;
}
?>
<div id="tertiary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-2' ); ?>
</div><!-- #tertiary -->
Now WordPress knows how to structure the sidebar. The last step will be telling WordPress when to use it all.
If you’d like your Portfolio Page (any page you assign the Portfolio Template to) to display this sidebar, you’ll need to look in the parent theme again. This time, copy the page-templates
folder into your child theme. Open that folder and edit your new copy of portfolio-page.php
.
We’re going to add a line of code to this file so the sidebar gets displayed. Near the bottom, just before
<?php get_sidebar( 'sidebar' ); ?>
add this line:
<?php get_sidebar( 'left-sidebar' ); ?>
Now any widgets you add to Left Sidebar will be displayed on your Portfolio page.
We’ll also need a bit of CSS to fix the alignment:
#tertiary.widget-area {
float: left;
}
Add that to the child theme’s style.css
.
Give that a try and let me know how it goes ??
-
This reply was modified 8 years ago by
Kathryn Presner. Reason: fix code formatting
-
This reply was modified 8 years ago by
Kathryn Presner. Reason: fixed code formatting