- This topic has 15 replies, 3 voices, and was last updated 6 months, 4 weeks ago by
David.
-
AuthorPosts
-
August 24, 2022 at 3:42 am #2322183
Rebecca
Hello,
I’m wondering if there is a way to use Elements and/or hooks to achieve the attached layout. I’m testing with the sidebar/content/sidebar layout, but would like the left sidebar to be below the featured image, and the right sidebar to be aligned with the featured image. I’ve attached a screenshot from another theme I’m testing (but want to stick with GP!). Thanks!
Here is a link to the image as I’m not sure the IMG tag worked: https://app.box.com/s/ht330l5ihessvh05m4q3y7gc1r1n7tc4
August 24, 2022 at 4:22 am #2322212David
StaffCustomer SupportHi there,
not sure, as thats a tricky one – if it is possible, will this be across the entire site ? Including archives ? ( please say no that last one lol )
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 4:25 am #2322215Rebecca
Hi David,
Ha! No this would only be for posts…August 24, 2022 at 4:40 am #2322231David
StaffCustomer SupportOK, so it will probably take some tweaking but try this:
1. Activate the Blog Module in Appearance > GeneratePress
2. In Customizer > Layout > Blog -> Featured images –> Posts tab set the Location to Before Title.
3. In Customizer > Layout > Sidebars – set your posts to just
Content / Sidebar
4. Create a new Hook Element.
4.1 Add this to the Hook:<?php get_sidebar( 'left'); ?>
4.2 Select the
generate_after_content
hook.
I choose this hook as i assumed on mobile you would want the left sidebar below the post content.4.3 Check Execute PHP.
4.4 Set the Display Rules to Posts > All Posts.
5. Add this CSS to your site to create the CSS grid layout:
/* Force left sidebar to fill the column */ .single-post .inside-article .is-left-sidebar { width: 100%; } /* remove padding from left sidbar widgets */ /* because the sidebar is inside the entry content */ .single-post .inside-article .is-left-sidebar .widget { padding: 0; } /* Apply a CSS Grid to create the article layout */ @media(min-width: 769px) { .single-post .inside-article { display: grid; grid-template-columns: 300px 1fr; /* Adjust 300px for sidebar width */ } .single-post .inside-article>* { grid-column: 2; } .single-post .inside-article .featured-image { grid-column: 1 / -1; } .single-post .inside-article .is-left-sidebar { grid-column: 1; grid-row: 2 / 1000; width: 100%; padding: 0; } }
If that works, and i can see it on your site then i can help with tweaking it.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 24, 2022 at 12:39 pm #2322807Rebecca
Thanks, that worked very well! I’m still formatting the actual sidebar content — is that available through widgets only? I’m getting errors using the Generateblocks Pro Query loop there (but that might be a separate issue I can open on that forum).
Two questions related to the overall CSS/Styling:
Is it possible to make it sticky?
When reducing the page, the right sidebar covers the contentI’ll include a link in the private area as it requires a login to view on staging.
Thanks!
August 24, 2022 at 5:53 pm #2323007Fernando Customer Support
Hi Rebecca,
Aside from Appearance > Widgets, you can also use a Block Element – Sidebar: https://docs.generatepress.com/article/block-element-sidebar/
You can try adding this CSS to make the last widget in the right sidebar sticky:
.inside-right-sidebar { height: 100%; position: relative; } .inside-right-sidebar > *:last-child { position: sticky; top: 5px; }
As for the second issue, try updating the code previously used to this:
/* Force left sidebar to fill the column */ .single-post .inside-article .is-left-sidebar { width: 100%; } /* remove padding from left sidbar widgets */ /* because the sidebar is inside the entry content */ .single-post .inside-article .is-left-sidebar .widget { padding: 0; } /* Apply a CSS Grid to create the article layout */ @media(min-width: 769px) { .single-post .inside-article { display: grid; grid-template-columns: minmax(0, 1fr) 300px; /* Adjust 300px for sidebar width */ } .single-post .inside-article>* { grid-column: 2; } .single-post .inside-article .featured-image { grid-column: 1 / -1; } .single-post .inside-article .is-left-sidebar { grid-column: 1; grid-row: 2 / 1000; width: 100%; padding: 0; } }
August 25, 2022 at 3:20 am #2323300Rebecca
Hi Fernando,
Thanks for the reply!
For the first point (using a block element for the left sidebar), I’m not sure that will work because my layout is content/sidebar, and then a grid is formed in the content area to create the left sidebar according to David’s directions above. However, let me know if I’m misunderstaning.
For the second point with code, that helped a great deal! My only question here is that the left sidebar is way too wide. I tried tweaking the 300px sidebar width in the code but it doesn’t help. How can I reduce this size? I’d actually like it narrower than the right sidebar. For example, 20% vs 30%
Thanks!
August 25, 2022 at 4:13 am #2323338David
StaffCustomer SupportSo this line:
grid-template-columns: minmax(0, 1fr) 700px;
Flip the values eg.
grid-template-columns: 250px minmax(0, 1fr);
Now you can change the 250px to whatever fixed size you want your sidebar.
Regarding a Block Element instead of a sidebar, yes, it can be done. Is there a benefit of doing so here? e.g you want a a left sidebar for your single posts, and a different left sidebar elsewhere
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 25, 2022 at 9:24 am #2323773Rebecca
This is perfect, thanks so much!!
I’m considering the Block Element for my left sidebar because I’m getting an error using the query loop in the widget area “This block has encountered an error and cannot be previewed.”
I don’t get this error when using the query loop in a block setup.
August 25, 2022 at 9:30 am #2323781David
StaffCustomer SupportIs that a GeneateBlocks Query Loop block? And does it work ok in the Right Sidebar ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 25, 2022 at 9:57 am #2323815Rebecca
Yes it’s GenerateBlocks Pro query loop. It works fine in the right sidebar which I created using a Block. It seems to not work when creating the left sidebar under appearance->widget.
August 25, 2022 at 10:41 am #2323857David
StaffCustomer SupportHmmm… i wondering whether its because we’re ouputting the sidebar inside the loop. We end up with a loop inside a loop.
But lets try the BLock Element.
So step 4 above if you quick edit and save that hook element as a draft.Then create a block element using the same Hook.
And the first thing to add to the block element is a container block, and in its Advacned > Additional CSS Class(es) add:is-left-sidebar
Then you can build inside that.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 25, 2022 at 10:56 am #2323868Rebecca
Yes that worked! Thank you, I greatly appreciate all of the help!
August 25, 2022 at 11:10 am #2323878David
StaffCustomer SupportOne last thing ๐
This CSS:
.single-post .inside-article .featured-image { grid-column: 1 / -1; }
change it to:
.single-post .inside-article .featured-image { grid-column: 1 / -1; padding-left: 0; }
That will get the featured image aligned nicely.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 25, 2022 at 11:17 am #2323885Rebecca
Perfect!! Thanks again ๐
-
AuthorPosts
- You must be logged in to reply to this topic.