- This topic has 12 replies, 3 voices, and was last updated 4 years, 6 months ago by
David.
-
AuthorPosts
-
September 30, 2021 at 4:26 pm #1948727
Len
I am trying out the new elements Layout and Blocks to create templates for custom post types, archives and taxonomies.
I want a different sidebar with specific widgets for this set of templates.
The Blocks Content sorts out the content.
Is there a way to create a sidebar with these templates, or set a specific sidebar to them using elements?Thanks
LenWSeptember 30, 2021 at 7:08 pm #1948789Elvin
StaffCustomer SupportHi LenW,
Block Element has templating types which includes creating a template for right and left sidebar – https://share.getcloudapp.com/Z4ujOvqw
You can create a layout within a Block element that will replace the default Left/Right sidebar if applied.
You can create multiple Block elements for the right sidebar and assign each of the Block elements to a different display rule location (for custom post types, archives and taxonomies)
October 4, 2021 at 2:52 am #1951864Len
Elvin
Just found where you got your image from! I have created a new block, element type sidebar and set location as my CPT and its archive.
Cleared the cache.
There is no new widget area to add widgets, which is what I am expecting with this. I don see the need for a block as such, other that to set margins for the sidebar. I have added a GP blue container to the sidebar, and a text block. This now appears on the CPT page.
I need just a widget area, where is the option to add that please?
Can you advise please, this is all very unclear.
Thanks
LenWOctober 4, 2021 at 3:30 am #1951912David
StaffCustomer SupportHi there,
to use a different widget area you will need to use a plugin like this:
October 4, 2021 at 6:11 am #1952035Len
Elvin
Further to this, I have now tried:
Added a new widget area in functions.php – this works, as I can see it if set
Added GP Hook to display the widget area: generate_after_right_sidebar_content – this works.
Does it matter if I use the before or after position?
Element template set to right sidebar, and location set for my CPT and archive. In the right sidebar element pus nothing at all.In Appearance > Widgets, added a container with 0 padding, CSS class set to “widget” then added a title and widget into the container. This then takes the styles as set in the customiser. I have used new widgets, not the legacy widgets.
Got a padding issue with widgets, compared to standard right widget area.The new widget area is inside the existing but empty sidebar widget area when I look at the code in the inspector, not replacing the existing sidebar. So I have the following:
div class=”widget-area sidebar is-right-sidebar grid-20 tablet-grid-20 grid-parent”
div class=”inside-right-sidebar”
div class=”primary-sidebar widget-area sidebar”This is messing up the css. Also, in the standard right sidebar, all widgets are in aside tags, these are not present in the new sidebar.
How do I fix this please?
The remaining issue is to display recent posts for my CPT, the WordPress standard widget only deals with the “posts”.
Thanks, LenW
October 4, 2021 at 6:52 am #1952063Len
Finally sorted this.
When registering the widget area, set:
‘before_widget’ => ”,
‘after_widget’ => ”,
This allows the “last” to work and then the margin between widgets.With the “new” Gutenberg widget blocks, always start with a GP blue container setting the class to widget.
Added sitewide CSS to suppress double padding, this to take account of the original sidebar above.
.widget .widget {padding:0!important}In the block – right sidebar element, have no blocks at all. Its there to provide the outer area.
The element Hook to display the widget area.So its almost all in GP, but messy to work out and implement.
Can you please consider an easier way to do this with the Elements.LenW
October 4, 2021 at 8:26 am #1952352Len
David
What’s confusing is which bits of GeneratePress are needed to implement a sidebar specific for a custom post type and archives, and what extra is needed so that the sidebar either confirms to the same style as the customiser, or has a different style.
I think I have done in php in functions.php what the custom-sidebars will do, unless that sorts out removing the original sidebar.
LenW
October 4, 2021 at 9:00 am #1952397David
StaffCustomer SupportYeah it can be a little confusing.
When you use a Block Element to replace the sidebar its removing the sidebar template altogether and just hooking into the same area. Which means the default themes sidebar HTML and the necessary classes for Customizer styling don’t exist.If you use the Block Element you would have reconstruct the HTML and CSS which is best done with the GenerateBlocks plugin.
Currently Blocks and Block Elements don’t support widget areas although there is a plugin that does provide Widget Area Blocks if you need to support standard widgets:
October 5, 2021 at 3:20 am #1953049Len
David
Can you explain this bit please.
“If you use the Block Element you would have reconstruct the HTML and CSS which is best done with the GenerateBlocks plugin.”
I started with a GenerateBlocks container in the Block – Right Sidebar element, but then removed it as it did nothing other than add divs.
I am not clear how the https://wordpress.org/plugins/organic-widget-area-block/ plugin helps.
Is there a simpler way?I added the widget area with:
Hook
generate_before_right_sidebar_content
using this php code (tags removed for this post):?php if ( is_active_sidebar( ‘books_sidebar_1’ ) ) : ?
div id=”books_sidebar” class=”primary-sidebar widget-area sidebar” role=”complementary”
?php dynamic_sidebar( ‘books_sidebar_1’ ); ?
/div><!– #primary-sidebar —
?php endif; ?Set up the widget area in functions.php.
So with the classes included, this appears to take the customiser settings for widgets that support it.
LenW
October 5, 2021 at 6:18 am #1953196David
StaffCustomer SupportTo cover:
1. The theme by default Hooks in the sidebar widget area.
2. When you use a Block Element – Sidebar it removes the sidebar widget area. Which limits you to adding just the Block content in the block element.
3. The Organic Widget Area Block, provides a block that adds a custom Widget Area.So using #2 and #3 will allow you can design your own sidebar container, add static or dynamic block content directly in the Block Element as well as inserting a widget area using the Organic Block area.
Overall by using the Block Element – Sidebar you’re detaching all controls provided by the Customizer aside from whether a sidebar is displayed or not.
October 5, 2021 at 9:21 am #1953654Len
David
OK, I think I understand.
However, what I have done seems to have acheived the same thing.
The website is a testing website, so locked behind WP Maintenance.Thanks for your patience with this!
LenW
October 6, 2021 at 12:59 am #1954289Len
David
Further to this discussion, and after checking out a few plugins for support, reviews, function etc, I now have a simpler way to get a specific sidebar on a custom post type / tax template.
1. Set up the content template in GP Elements
2. Use plugin Easy Custom Sidebars to create a specific sidebar to replace a sidebar on the CPT and CPT archives and taxonomies.This now avoids php code in a GP Element hook to create a sidebar, and the GP Element to remove a sidebar where not wanted, and no messing with css classes either.
It would be good for this to be simply achieved in GeneratePress
LenW
October 6, 2021 at 4:44 am #1954490David
StaffCustomer SupportWe looked at dynamic widget areas for GB elements, but we considered the future of Full Site Editing and expect that in the future most Widgets ( core and 3rd party ) would be updated to provide block based versions. Which would eliminate the need for classic widget areas as you could simply add them as Blocks in a GP Block Element Sidebar.
Glad to hear you found a plugin you like and have a working solution!
-
AuthorPosts
- You must be logged in to reply to this topic.