Stared a Wordpress site using Underscores theme (_s)
I have got one sidebar working but want to make a second one to be on the same page. (containing different widgets)
I have added the new sidebar to the functions.php and it appears in the Wordpress login screen and i can drop widgets into it. However, I can't get it to show on the actual webpage. (the first sidebar is working fine)
Anyone know how to do this or know a tutorial...
Thanks
You'll need to edit the "sidebar.php" file in your theme folder. It should normally be:
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
</div><!-- #secondary -->
You will need to add another if statement that looks out for the other sidebar. Be sure to reference it by whatever you used in the functions.php file.
If you want it to appear below the current sidebar, just be sure to add it before closing the 'div' so it will still be in the same column. I used 'sidebar-lower':
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar-1 widget area ?>
<?php if ( ! dynamic_sidebar( 'sidebar-lower' ) ) : ?>
<?php endif; // end sidebar-lower widget area ?>
</div><!-- #secondary -->
Related
Im using the UnderScore theme and below is the main page.php template file. What im aiming for is if there is active widgets in the sidebar use template with sidebar but if no active widgets or content use template that has the main content as 960px with no sidebar. Im also using ACF (advance custom fields) is the sidebar so would need to check that aswell. Gratefull for any help. I thought maybe using "is_active_sidebar" but unsure how to implerment it properly as template parts are already being check.
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
Also below the sidebar.php
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
<?php the_field('sidebar_info'); ?>
</aside><!-- #secondary -->
Maybe I'm not fully understanding you question, but you can use a simple if-statement for that. See pseudo code below.
if ( active widgets in the sidebar ) {
// use this formatting
} else {
// use that formatting
}
I am looking for help to remove "junk" widgets from my wordpress website. Website theme is Zerif Lite and on every page so far there was no sidebar,however when I make a new post there is alot of junk (sidebar,who posted it,when,how entry was tagged and replay option).
I tried removing it from appearance->widgets and it didnt work and theme customization for widgets is locked for lite version.
So for start I 1st want to remove sidebar that include search,archives and meta.Only thing that worked so far was blanking out sidebar.php that include:
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h2 class="widget-title"><?php _e( 'Archives', 'zerif-lite' ); ?></h2>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h2 class="widget-title"><?php _e( 'Meta', 'zerif-lite' ); ?></h2>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; ?>
</div><!-- #secondary -->
However when I did that sidebar was removed,but space it took was blank,meaning post itself was only using 2/3 of page.
To get you to see for your self here are links to site (its in serbian,ignore that):
website and:
new post, this you can only see with this link,its where problem is
So if anyone can help me remove all that and make page clean I would be very greatfull. Thanks
The problem is css
Here is the solution (only if you dont use sidebar anywhere in your site)
Change the width of your content container, maybe right now is set to 70%(remaining 30% is for sidebar) to 100%.
If you plane to use sidebar, then you need set a conditional class in your functions.php:
function custom_body_classes( $classes ) {
// Adds a class of nosidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'nosidebar';
}
return $classes;
}
add_filter( 'body_class', 'custom_body_classes' );
Then only customize the css with the new class. Ex:
.content .nosidebar {
width:100%
}
Cheers
my blog page in Wordpress is using a specific widget but I wanted to use different widget for a post in the blog.
I used an example (https://gist.github.com/anonymous/1308851) to write my code in sidebar.php.
<?php
if ( 'content' != $current_layout ) :
?>
<?php
//for rest of posts
if (is_active_sidebar('blog_widget_area') ) : ?>
<div id="secondary" class="blog_widget_area bordered" role="complementary">
<?php dynamic_sidebar( 'blog_widget_area' ); ?>
</div><!-- #secondary .widget-area -->
<?php endif;
//for specific post "Loyalty Program Trends in the Restaurant Industry"
if (is_active_sidebar('loyalty_programs_widget_area') && is_single('4063') ) : ?>
<div id="secondary" class="blog_widget_area bordered" role="complementary">
<?php dynamic_sidebar( 'loyalty_programs_widget_area' ); ?>
</div>
<?php endif;
?>
<?php endif; ?>
However, I couldn't get the second widget to display in that specific post....
Possible solutions:
Before trying below solution make sure some data/widget already loading on sideabar
loyalty_programs_widget_area.
solution 1
// use array inside is_single function
<?php if (is_active_sidebar('loyalty_programs_widget_area') &&
is_single( array('4063','4063-page-name-here') ) ) : ?>
<?php endif; ?>
solution 2
// put separate if check inside sidebar
<?php if (is_active_sidebar('loyalty_programs_widget_area') ) : ?>
if( is_single('4063') ) { } or
if( is_single(array('4063','pagename')) ) { }
<?php endif; ?>
Other possible solutions:
Try:
-deactivating ALL plugins temporarily to narrow down and possibly fix the problem . If the problem goes away, activate them individually to find the culprit?
-switching to the default theme (Twenty Ten) for a moment by renaming your current theme's folder in wp-content/themes. The idea is to force WordPress to fall back to the default theme to rule out any theme-specific issue?
For further details read official documentation regarding " sidebar "
Note:
is_single() offer different other ways to check post id or name(when permalink isenabled)
- is_single(array(17,'beef-stew','Irish Stew'));
- is_single('17'); or is_single(17);
Try this code below:
<?php // only show on 31 post not any other. ?>
<?php if ( is_single('31') ) { ?>
<?php // if blog_widget_area2 is active then show otherwise don't :) ?>
<?php if ( is_active_sidebar( 'blog_widget_area2' ) ) : ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area2"); ?>
</div>
<?php endif; ?>
<?php }else{ // otherwise load this sidebar ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area"); ?>
</div>
<?php } ?>
With the help of codewizz (Thanks codewizz!), we got it to work. The things we need to change is to move the code over from sidebar.php to single.php. However, the way it's coded, it displays both the first widget and the second widget on the post's sidebar.
So he suggested that I use http://wordpress.org/plugins/display-widgets/. And now it works.
Additionally, if one want to start from scratch, you should use that code
<?php // only show on 31 post not any other. ?>
<?php if ( is_single('31') ) { ?>
<?php // if blog_widget_area2 is active then show otherwise don't :) ?>
<?php if ( is_active_sidebar( 'blog_widget_area2' ) ) : ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area2"); ?>
</div>
<?php endif; ?>
<?php }else{ // otherwise load this sidebar ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area"); ?>
</div>
<?php } ?>
I'm trying to output a sidebar in Wordpress depending on whether it has widgets (is active) or not and to display them on my Shop page accordingly.
I'm pretty unfamiliar with PHP, and so far have written up the following scripts to try and make this work, but it doesn't seem to be happening.
shop.php:
<?php
/**
* The template for displaying the Shop page.
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php shop_content(); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar('shop'); ?>
<?php get_footer(); ?>
sidebar-shop.php:
<?php
/**
* The sidebar containing the Shop page widget areas.
*
* If no active widgets are in the sidebars (Left, Right and theShop),
* the sidebars should be hidden completely.
*/
?>
<?php
// If the left, shop and right sidebars are inactive
if ( ! is_active_sidebar( 'right-sidebar' ) && ! is_active_sidebar( 'shop-sidebar' ) ) {
return;
}
// If there are active widgets in the Shop Sidebar
if ( is_active_sidebar( 'shop-sidebar' ) ) { ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'shop-sidebar' ); ?>
</div><!-- #secondary -->
<?php
}
// If there are active widgets in the Right Sidebar
elseif ( is_active_sidebar( 'right-sidebar' ) ) { ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
</div><!-- #secondary -->
<?php
}
?>
sidebar.php:
<?php
/**
* The sidebar containing the main widget area.
*
* If no active widgets in sidebar, let's hide it completely.
*
*/
?>
<?php if ( is_active_sidebar( 'right-sidebar' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
</div><!-- #secondary -->
<?php endif; ?>
How would I modify the script above to output the following:
if the Right Sidebar (right-sidebar) has widgets, display the Right Sidebar
if the Shop Sidebar (shop-sidebar) has widgets, display the Shop Sidebar
if the Right Sidebar and Shop Sidebar both have widgets, display the Shop Sidebar
if neither the Right Sidebar or the Shop Sidebar have any widgets, don't display anything
Thank you.
// if both are active shoe shop
if (is_active_sidebar('shop') && is_active_sidebar('sidebar-1')) {
get_sidebar('shop');
}
//if shop is active, show shop
elseif (is_active_sidebar('shop')) {
get_sidebar('shop');
}
// if sidebar 1 is active show it.
elseif (is_active_sidebar('sidebar-1')) {
get_sidebar('sidebar-1');
}
Code should be simple, because you have defined good precedence of Shop sidebar over right sidebar. You don't need to worry if you don't need to display the sidebars.
<?php
// If shop sidebar is active, it takes precedence
if ( is_active_sidebar( 'shop' )){
get_sidebar( 'shop' );
}
elseif (is_active_sidebar( 'sidebar-1' )){
get_sidebar( 'sidebar-1' );
//This is "shop side bar is inactive and right sidebar is active"
}
// That's all; just two condition blocks!
?>
Thanks.
It is being modified by the functions.php file.
I've tried many variations and can't seem to get the syntax right. In one of my Wordpress theme pages I have the following Widget code. I want to append the existing functionality to where it removes this widget if the page name is 'event-view' or page id is '640'...how do I do this?
<?php
// A third sidebar for widgets
if ( is_active_sidebar( 'third-widget-area' ) ) : ?>
<div id="third" class="widget-area" role="complementary">
<ul class="xoxo">
<?php dynamic_sidebar( 'third-widget-area' ); ?>
</ul>
</div><!-- #secondary .widget-area -->
Try this:
<?php
// A third sidebar for widgets
if ( is_active_sidebar('third-widget-area') && !is_page(640) ) : ?>
<div id="third" class="widget-area" role="complementary">
<ul class="xoxo">
<?php dynamic_sidebar( 'third-widget-area' ); ?>
</ul>
</div>
You can also check page by it's name is_page('event-view')
try changing
if ( is_active_sidebar( 'third-widget-area' ) )
to
if ( is_active_sidebar( 'third-widget-area' ) && !is_page(640) )
this way you can check if the current page is any other than the one with the id 640; see http://codex.wordpress.org/Function_Reference/is_page
Try out this.
You can give pass page_id in is_page() function.
if(is_page('640') || is_page('49'))
And for more details see below.
http://wordpress.org/support/topic/display-widget-on-certain-pages