I'm having difficulty with setting up a second sidebar for my Wordpress theme.
Here's the code for function.php:
<?php
if(function_exists('register_sidebar')){
register_sidebar(array(
'before_widget'=>'<li>',
'after_widget'=>'</li>',
'before_title'=>'<h2>',
'after_title'=>'</h2>',
))
;
}
?>
<?php
if(function_exists('register_sidebar')){
register_sidebar('home'array(
'before_widget'=>'<li>',
'after_widget'=>'</li>',
'before_title'=>'<h2>',
'after_title'=>'</h2>',
))
;
}
?>
This is the error I'm receiving when I try to access the widget options page in admin:
Parse error: syntax error, unexpected
T_ARRAY in
C:\xampp\htdocs\tlc\wp-content\themes\tlc\functions.php
on line 14
to give it a name you use this syntax
register_sidebar(array(
'name' => 'RightSideBar',
'description' => 'Widgets in this area will be shown on the right-hand side.',
'before_title' => '<h1>',
'after_title' => '</h1>'
));
not what you wrote
see this for more info
http://codex.wordpress.org/Function_Reference/register_sidebar
Related
I have managed to follow fuxia's solution on adding a default widget to the footer sidebar but the widget doesnt seem to be "activated" (I have to remove and manually add it back to the footer sidebar for the widget to work, making the pre-set widget code pointless). I found that the widget added by the aforementioned solution and the same widget pulled from the list of available widgets are different. The picture below shows different href values for the widget items in the footer list of widgets. (Grey boxes are just the widget name)
I'm not sure if this is the reason behind the issue but is there a way to add the widget to the footer sidebar AND have it work/"activated"?
EDIT: current implementation
add_action( 'widgets_init', function(){
register_widget( 'MyWidget' );
$sidebars = array ('a' => 'sidebar-1' );
foreach ( $sidebars as $sidebar ) {
register_sidebar(array (
'name' => 'Footer',
'id' => $sidebar,
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>'
));
}
$active_widgets = get_option( 'sidebars_widgets' );
if ( ! empty ( $active_widgets[ $sidebars['a'] ] )){
return; }
$counter = 1;
$active_widgets[$sidebars['a']][0] = 'my_widget-'.$counter;
update_option('sidebars_widgets',$active_widgets);
dynamic_sidebar('sidebar-1');
}
Can you check with the following code?
functions. php
add_action( 'widgets_init', 'custom_sidebars' );
/*Custom widgets*/
function aavishkaar_custom_sidebars(){
register_sidebar(
array (
'name' => __( 'Footerwidget', 'Aavishkaar' ),
'id' => 'footer-widget1',
'description' => __( 'Footer widget', 'Aavishkaar' ),
'before_widget' => '<div class="col-md-2 col-3 footer-pd_0 widget_ul">',
'after_widget' => "</div>",
)
);
}
Then add menu to this and call it by <?php dynamic_sidebar('footer-widget1');?>
I'm new to Wordpress and just created my first template.
In the functions.php I have put the following code, that function what I understand should call the plugins from the plugins directory:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Widgetized Area',
'id' => 'widgetized-area',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
}
I do see all the plugins, and in the widget screen I also see the 'widgets' screen and it allows me to drag widgets into the working area.
The website itself displays the plugin's html but neither js nor css is working.
What am I missing?
Above code that you have added in your functions.php is to register sidebar not to call any plugin. It do not have any connection to plugin.
You can call sidebar you added in template as follow:
if ( is_active_sidebar( 'widgetized-area' ) ) {
dynamic_sidebar( 'widgetized-area' );
}
I am following this guide to "Add additional support for menus in your theme":
http://codex.wordpress.org/Navigation_Menus
I followed all of the steps, but this is the result:
http://puu.sh/30bMt.png
So, it's "inserting a menu" where I told it to.... however the items on the menu do not match up with what I have in the WordPress back-end, seen here...
http://puu.sh/30bQd.png
I only inserted 4 items into the menu "Test"... but it's displaying every page, instead of the 4 items I want.
I've attempted to do research to figure out what's going on to no avail; does anybody have any insight as to why this is acting funky?
Code where I'm "registering" the additional menu support... (themes function.php):
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Code where I'm inserting the "Header Menu" itself... (themes header.php):
<?php
wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' =>'my_extra_menu_class' ) );
?>
If you are trying to call 'Header Menu' then the code in your header.php should look like this:
<?php wp_nav_menu(array('theme_location' => 'header-menu', 'menu_class' => 'my_extra_menu_class')); ?>
I'm not sure where you got 'extra-menu' from but WordPress doesn't know what that is since you didn't declare that in your register_my_menus function.
I hope that helps.
Here's an example of how I've implemented multiple menus in my WordPress install:
// Register Extra Menus
function new_register_menus() {
register_nav_menus(array('Products'=>'Products Nav', 'Support'=>'Support Nav', 'Company'=>'Company Nav' , 'Footer'=>'Footer Nav'));
}
add_action( 'init' , 'new_register_menus' );
//Code in my footer.php
<?php wp_nav_menu(array('theme_location' => 'Footer', 'menu_class' => 'nav')); ?>
my url looks like this:
http://domain.com/?s=searchquery&post_type=qa_faqs
that page lists search results for "searchquery".
i then get the post type with
$post_type = $_GET['post_type'];
it echoes correctly
echo $post_type;
// Provides: qa_faqs
i then do an if/else to display a different menu via wp_nav_menu when $post_type is qa_faqs.
if ( $post_type == 'qa_faqs' ) {
echo 'we got qa_faqs over here';
wp_nav_menu(array('menu' => 'meta_menu', 'items_wrap' => '<dl id="%1$s" class="nice tabs vertical %2$s">%3$s</dl>', 'walker' => new sidenav_walker ));
} else {
echo 'no qa_faqs in da house';
wp_nav_menu(array('menu' => 'service_menu', 'items_wrap' => '<dl id="%1$s" class="nice tabs vertical %2$s">%3$s</dl>', 'walker' => new sidenav_walker ));
}
now to the funny part:
even though the page echoes 'we got qa_faqs over here', it displays the service_menu.
why´s that?
Found it - http://codex.wordpress.org/Navigation_Menus
Same problem was driving me nuts aswell.
Use 'theme_location' instead of 'menu' to point to which menu you want to output.
Try targetting the specific menu with something like:
<?php wp_nav_menu( array('menu' => 'Your Menu Name' )); ?>
I think you dont have any items on the meta_menu. Please create menu under Appearance section and assign it. :)
Custom sidebars has been a breeze so far except with it comes unto the blog 'Category'.
Notice how it looks perfectly here on the 'Page' version - http://70.87.35.71/~life/?page_id=87
but the same sidebar has different elements the category version - http://70.87.35.71/~life/?cat=1
Why does the sidebar look so crappy when under the category section and how do I make it look like the 'Page' version.
My sidebar code is below
<div id="sidebar" class="clearfix">
<?php
if ( !in_category('1') ) {
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') )
{}
}
else {
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Blog') )
{}
}
?>
</div> <!-- end sidebar -->
There is no need to check if function_exists. It has existed since WordPress version 2.1.
Your display problem is due the sidebar blog sidebar not being registered properly.
add_action( 'widgets_init', 'add_blog_sidebar' );
function add_blog_sidebar() {
register_sidebar(array(
'name' => 'Blog Sidebar',
'id' => 'blog',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
}
The before widget and before title arguments are needed to allow for styling.
Calling your dynamic sidebar:
if ( is_category('1') dynamic_sidebar( 'blog' );
else dynamic_sidebar( 'sidebar');
To learn everything there is to know about sidebars check out Justin Tadlock's sidebar tutorial.
Try changing it to:
<?php
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Blog') )
{}
?>
remove the if else statement.