How can I add sidebar manually?

6.55K viewsCore
0

Hello.
I want to add sidebar manually at the right side because sidebar widget is not working. Currently I’m editing `base.php` inside of default theme.

<?php dynamic_sidebar( 'ap-top' ); ?>
<div style='width:100%;height:30px;background:#333;'>

</div>
<div id="ap-lists" class="clearfix" style='width:80%; float:left;'>
	<?php ap_questions_tab(get_permalink()); ?>
	<?php if ( $questions->have_posts() ) : ?>
		<div class="question-list">
	<?php
		
		/* Start the Loop */
		while ( $questions->have_posts() ) : $questions->the_post();
			global $post;
			include(ap_get_theme_location('content-list.php'));
		endwhile;
	?>
		</div>
	<?php 
		ap_pagination();
	?>
	<?php
		else : 
			include(ap_get_theme_location('content-none.php'));
		endif; 
	?>	
</div>

<div style='width:20%;height:100px;background:#444;float:right;'>
	`Can I add here sidebar widget ?`
	
</div>

Thank you very much.

1

Okey, Janob simply do this:
Create a new directory in active theme (not child theme) as anspress now copy base.php file to newly created folder.
Now pastes this code to base.php:

<?php dynamic_sidebar( 'ap-top' ); ?>
<div id="ap-lists" class="clearfix">
	<?php ap_questions_tab(get_permalink()); ?>
	<?php if ( $questions->have_posts() ) : ?>
		<div class="question-list">
			<?php
				
				/* Start the Loop */
				while ( $questions->have_posts() ) : $questions->the_post();
					global $post;
					include(ap_get_theme_location('content-list.php'));
				endwhile;
			?>
		</div>
	<?php 
		ap_pagination();
	?>
	<?php
		else : 
			include(ap_get_theme_location('content-none.php'));
		endif; 
	?>	
</div>

<!-- Here goes your custom sidebar, add styles by yourself -->
<div class="my-sidebar">
<?php dynamic_sidebar('my-custom-sidebar' ); ?>
</div>

and now paste this code in your WordPress theme functions.php

add_action( 'widgets_init', 'mysite_widgets_positions' );
function mysite_widgets_positions(){
	
	register_sidebar( array(
		'name'         	=> __( 'My Custom Sidebar', 'ap' ),
		'id'           	=> 'my-custom-sidebar',
		'before_widget' => '<div id="%1$s" class="ap-widget-pos %2$s">',
		'after_widget' 	=> '</div>',
		'description'  	=> __( 'Widgets in this area will be shown in questions page sidebar.', 'ap' ),
		'before_title' 	=> '<h3 class="ap-widget-title">',
		'after_title'  	=> '</h3>',
	) );
}
You are viewing 1 out of 3 answers, click here to view all answers.