Wordpress - Different sidebar for each page - wordpress

Client needs an website to migrate into WordPress.
In this website each page has an sidebar with different content inside it
In some page accordion comes under sidebar, in some just text and images are visible
How to implement this in WordPress?
If template has to be created, there are many page it cant be done so
Even for every page different sidebar widget is not also possible
Guide me a way to implement this

A different sidebar (widget) are can be added to each page in two steps:
Add the sidebar to the theme template using the page slug as part of the sidebar name. This ensures that the sidebar has a unique name for that page.
Register the sidebars for each page in functions.php for your theme
Add the sidebar to the theme template
In your theme template, add the following code where you want the widget area to be:
<?php
global $post;
dynamic_sidebar( 'widget_area_for_page_'.$post->post_name );
?>
Register the sidebars
In functions.php for your theme add the following block of code to register the sidebars for each page in your site. Note that it includes draft pages etc so that you can edit the widgets while still in draft mode.
function myTheme_registerWidgetAreas() {
// Grab all pages except trashed
$pages = new WP_Query(Array(
'post_type' => 'page',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
'posts_per_page'=>-1
));
// Step through each page
while ( $pages->have_posts() ) {
$pages->the_post();
// Ignore pages with no slug
if ($pages->post->post_name == '') continue;
// Register the sidebar for the page. Note that the id has
// to match the name given in the theme template
register_sidebar( array(
'name' => $pages->post->post_name,
'id' => 'widget_area_for_page_'.$pages->post->post_name,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
}
add_action( 'widgets_init', 'myTheme_registerWidgetAreas' );
Hope it helps!

There's a great plugin for this:
https://wordpress.org/plugins/custom-sidebars/
Sometimes it is necessary to show different elements on the sidebars
for some posts or pages. The themes nowadays give you some areas to
put the widgets, but those areas are common for all the posts that are
using the same template. NOTE: You need to use a theme that accepts
widgets to make this plugin work.
I think this is what you're looking for.

This can be done with the https://wordpress.org/plugins/jetpack/ plugin. Once activated you can choose what widgets display on what pages:
The Widget Visibility module enables you to configure widgets to appear only on certain pages (or be hidden on certain pages) by using the Visibility panel.
Visibility is controlled by five aspects: page type, category, tag, date, and author. For example, if you wanted the Archives widget to only appear on category archives and error pages, choose “Show” from the first dropdown and then add two rules: “Page is 404 Error Page” and “Category is All Category Pages.”

Just tried custom-sidebars with the latest version of wp. Had a hard time deleting it. Database is still messy. Plugin did not work. Maybe the 'pro' version is useful, but the 'non-pro' version would not add a sidebar to the page. It was clunky and did not allow per-page sidebars. It says its not been tested with the latest wp, maybe that's the problem.

You can create custom sidebar for for each post and pages with the help of plugin. There are a few plugins which enables you to create your custom sidebar. Here in this tutorial we are using Easy Custom Sidebars. Download and install this plugin in your website and activate it.
After successfully activating the plugin go to Appearance > Sidebar Replacement
From this page give a name to your custom sidebar and click on the Create Sidebar button. After that go to the Sidebar Properties option. Here you need to select the properties where you want to replace your created custom sidebar instead of theme sidebar. You can view your available option in the drop-down menu. Select it and provide a description on the Sidebar Description field.
Now in the last step select the post or pages to add this custom sidebar. You can see all the option in the left column. You can select specific post, page, category , tag, author to add this sidebar. Just select it and click Add to sidebar option.
For better understanding you can follow this tutorial

Related

Wordpress plugin menu issue

I am building a wordpress plugin with the boilerplate framework (https://wppb.me/). That all works fine. I have an annoying issues which I cannot solve.
the boilerplate makes per object one php file. In this php file all funtionality for the object is arranged. Pages, lists, validations etc.
Example in the file for contact there is a method contactlog_menu:
Object: contact
public function contactlog_menu()
{
add_submenu_page('plugin-options', __('plugin', 'plugin'), __('am_contactlogs', 'plugin'), 'manage_options', 'contactlogs', array($this, 'plugin_contactlogs_page_handler'));
add_submenu_page('contactlogs', __('New contactlog', 'plugin'), __('Add new b', 'plugin'), 'activate_plugins', 'contactlogs_form', array($this, 'plugin_contactlogs_form_page_handler'));
}
Now it shows a menu option in the left menu of wordpress. I would like to remove this menu option and create a hyperlink on the dashboardpage to this page. If i remove the lines wordpress is telling me i have no permission to view the page. what am i missing here
So i want to remove the menu item but want to page to be accessible as a link on another page. Otherwise my menu will become very large :-).
I hope it is understandable, otherwise please ask..
If you use null for the parent_slug parameter the page won't show up in the menu.
add_submenu_page(
null,
'My Custom Submenu Page',
'My Custom Submenu Page',
'manage_options',
'my-custom-submenu-page',
'callback_function' );
The page will be accessible via any parent slug, as long as it exists:
https://yoursite.com/wp-admin/options-general.php?page=my-custom-submenu-page
https://yoursite.com/wp-admin/tools.php?page=my-custom-submenu-page
https://yoursite.com/wp-admin/index.php?page=my-custom-submenu-page
...
Or no parent slug at all (same effect as if you'd use index.php):
https://yoursite.com/wp-admin/?page=my-custom-submenu-page
But it's probably best to use admin.php for your hyperlinks (the menu item that belongs to the slug you use will be active - if you use admin.php no menu item will be active):
https://yoursite.com/wp-admin/admin.php?page=my-custom-submenu-page

Customizing my account page in woocommerce wordpress

When I customize the my account page in woocommerce, I can edit right side section by creating my_account.php inside my account folder in woocommerce. But In left side it is showing "Define your 'My Account' navigation Apperance > Menus",
After seeing this I tried to create menu called "My account", but there was no theme location existing, so I create a theme location called "my account menu". And I assign "my account" menu with theme location "my account menu".
I don't know how to connect this menu to my account page in woocommerce, the page again showing same "Define your 'My Account' navigation Apperance > Menus".
Try Appearance>Menus>Custom Links
Otherwise:
Is the theme you are trying to edit a pre-built theme?
Is the platform up-to-date or outdated (sometimes updates/bugs can alter functionality of pre existing code)?
Sometimes there are errors in the theme build, as I have seen. In such a case, I would recommend reaching out to the theme developer(s) as they can usually help the best in this situation. If not, check back. Hope this helps.
Call menu by menu name instead of theme_location
<?php wp_nav_menu( array( 'menu' => 'Main Menu' ) ); ?>

Reposition elements in Wordpress post editor

I'm developing a wordpress website and I've added some custom fields. They work just fine, but I wanted to reposition them in the admin editor.
So for example you have the WYSIWYG editor with some little widgets on the side, like categories, publish widget and so on. Some of my custom fields are just checkboxes, so I was wondering if it was possible to put those in the admin sidebar, rather than sticking them underneath the WYSIWYG editor.
How can that be achieved?
Check the documentation for add_meta_box.
add_meta_box(
$id,
$title,
$callback,
$post_type,
$context,
$priority,
$callback_args
);
$context - The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').

WordPress: How to make the 'Theme Options Page' appear on the 'Edit Page'?

Just in case, here's what Theme Options Pages are in WordPress:
http://css.dzone.com/articles/how-create-theme-options-page
I've been racking my brain trying to figure out how to get the Theme Options Page of any WordPress theme to appear on the 'Edit Page' of WordPress. Does anyone know how to do this so each page I create would have different results when published?
I think your problem here is that really WordPress is setup to have a single theme with a single set of options, what your trying to do is essentially have a new theme for each page.
Instead, you probably need individual Page Templates for those options that you would like to customize on a page by page basis (e.g. Blue Background, White Background, Large Logo etc).
If you'd like to have a series of options that are easy to adjust on the fly, you could set up some Custom Fields and then adjust your template to pull settings from them as needed.
First, define action like this:
function mytheme_customize_register( $wp_customize ) {
}
add_action( 'customize_register', 'mytheme_customize_register' );

how to list subpages in sidebar without widget - wordpress

I am trying to create a list of subpages of a parent page, which will appear in the sidebar of my wordpress site. This sidebar will appear on every page.
So for example, I have a page with an ID of 54. This page has 7 subpages. I would like to display these 7 pages in the sidebar (just the titles), as well as any more subpages that get added.
There is a currently a widget called 'Pages' that will do this, but I would like to do this via code directly in the sidebar.php rather than using a widget as there are a few constraints with using the widget.
Any help would be greatly appreciated.
Thanks
Try this link: http://codex.wordpress.org/Function_Reference/wp_list_pages
Specifically, look the 'depth' and 'child_of' parameters for the function.
Should be:
<?php wp_list_pages( array( 'depth' => 1, 'child_of' => YOUR_PAGE_ID_HERE ); ?>
furthermore, you can get the page id dynamically too of course.
To write custom code for such purpose will require you to execute php inside the widget. Try using this Php Code Execute Plugin

Resources