- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
March 12, 2023 at 4:46 pm #2565287
Pete Williams
I’ve created a ‘Block – Content Template’ to allow me to control the width of certain pages/posts that are different to those set in the theme customiser options.
The Content Template includes a Container (to control the width) and a Dynamic Content block to pull in the post content. It works perfectly, but it prevents ‘Block – Hook’ elements that are set to appear at certain Hook locations from displaying.Is there a simple way to ensure that these hooks continue to display without relying on shortcodes?
If a different approach is required, I’m happy to look into that too.
Basically, I’d just like the posts/pages to work as default with all hooks active, but still be able to select various widths i.e Other than contained and full-width.
Many thanks for your help.
Kind regards,
PeteMarch 12, 2023 at 5:16 pm #2565302Ying
StaffCustomer SupportHi Pete,
The
block element - content templateis not supposed to be used in this circumstance.In your case, you’ve replaced the entire content template which has hooks inside with a container and the content block.
Try disabling the content template and using a layout element instead:
https://docs.generatepress.com/article/layout-element-overview/#content-1March 13, 2023 at 1:31 pm #2566474Pete Williams
Hi Ying,
Thanks for the reply.
I can’t get it to work with a Layout Element, either.
If I set the Layout Element to my preferred width, it works great when the Sidebar layout, ‘No Sidebars’, is selected but becomes too narrow when the Sidebar layout, ‘Right Sidebar’, is selected. It also prevents the on-page metabox option of Full Width Content Container from working. It limits the Full-Width to the width set in the Layout Element settings.
Without using a Layout Element, the ‘Right Sidebar’ layout and ‘Full Width’ Content works great, but then the ‘No Sidebars’ layout is too wide. I’d rather not have to keep editing an Element to exclude an additional post or page each time I create one that requires the third layout option.
Ideally, I’d like three different layout widths for both posts and pages.
- Full-Width – Content (no sidebars) without padding – So I can have full-width sections throughout the page/post and contain other text via container blocks.
- Contained (e.g. 1200px) – Content / Sidebar with padding – Typical blog post layout
- Contained (e.g. 800px) – Content (no sidebars) with padding – The content will go no wider than the set width
One solution that seems to provide a workaround:
Set up a custom taxonomy that I can apply to individual pages/posts, similar to the on-page metabox options, allowing me to tick a box to exclude the page/post from the layout element. This seems to be a slightly easier way to manage things rather than editing the layout element to exclude an additional page each time I need a full-width post.
This works, but it’s not ideal. Is there an easier way to achieve the three layouts selectable via the on-page metabox options rather than constantly editing Elements?
Kind regards,
PeteMarch 14, 2023 at 4:00 am #2567050David
StaffCustomer SupportHi there,
most of what the layout metabox / elements do is to a) add a body_class and b) write some CSS to the page.
For example, when you select:
Full Widthcontent it adds thefull-width-contentbody_class.
No Sidebarsit adds theno-sidebarbody_classSo a simple solution would be to add this CSS:
.no-sidebar:not(.full-width-content) #content { max-width: 800px; margin-left: auto; margin-right: auto; }Then when the page has
no-sidebarand is notfull-width-contentit will fix the width to 800px.The alternative method is one i provide here:
https://generatepress.com/forums/topic/display-rules-to-target-page-options/#post-2366988
March 14, 2023 at 11:56 am #2567696Pete Williams
Thanks, David.
I’d already set up your alternative method but was trying to apply a simpler method.
I’m embarrassed that I didn’t think of the CSS solution.
That’s worked a treat.
Thank you!
March 15, 2023 at 4:30 am #2568351David
StaffCustomer SupportYou’re welcome – glad to be of help.
-
AuthorPosts
- You must be logged in to reply to this topic.