- This topic has 5 replies, 2 voices, and was last updated 2 years, 3 months ago by Elvin.
-
AuthorPosts
-
January 9, 2022 at 3:30 pm #2074701Ema
Hello, Happy New Year to you all GP!
I’m just in the early dev stages of this particular site. I’m looking to have a Table of Contents on some of my CPT which have long-form content.
I’d like the to be sticky similar to MC’s this example
I have added the code
@media (min-width: 769px) { #right-sidebar { position: -webkit-sticky; position: sticky; top: 0; } }
But couldn’t get it to stick
Thanks in advanceEma
January 9, 2022 at 5:19 pm #2074758ElvinStaffCustomer SupportHi Ema,
I’m not exactly sure what TOC uses as its function to display the TOC on the sidebar but this PHP snippet can help.
add_action('wp_head', function(){ if( function_exists('the_TOC_function') ){ echo '<style> @media (min-width: 769px) { #right-sidebar { position: -webkit-sticky; position: sticky; top: 0; } } </style>'; } });
But you’ll have to replace
the_TOC_function
line of the code with what function TOC uses to output the table of contents. You can ask TOC’s support for this. ๐January 9, 2022 at 7:22 pm #2074838EmaHi Elvin, Thank you so much for your reply and time. Very appreciated.
I’ve found this
tutorial – which is using GP theme too.I am using Easy Table of Contents – but don’t think I need to use the Content-Aware plugin, as I am. making use of GPs Layout in Elements to only show a sidebar on certain posts.
EZ-Tocs docs say “To enable the option to affix or pin the Table of Contents widget enter the theme’s sidebar class or id.
Since every theme is different, this can not be determined automatically. If you are unsure how to find the sidebar’s class or id, please ask the theme’s support persons.
Eg: .widget-area or #sidebar”I’m going to be popping it into the left-sidebar – which for GP is ‘#left-sidebar’?
The tutorial uses the following code
/*This CSS code works for GeneratePress. You need to replace the class name of the sidebar with the class from your own theme
*/
.inside-right-sidebar { height: 100%; /* Make sidebar the full-height */ } aside.ez-toc { position: sticky; position: -webkit-sticky; /* Safari */ top: 50px; /* Offset from top of container */ }
Would I replace
`aside.ez-toc’ with #left-sidebar?Do you think I would still need a function?
Best Ema
January 9, 2022 at 10:25 pm #2074903ElvinStaffCustomer SupportAh there shouldn’t be any need for the function then.
And the guide itself should work as is w/ all the CSS selectors. ๐
January 12, 2022 at 6:41 am #2077865EmaHi Elvin, thanks for getting back to me. Will be trying to implement this shortly! I will report back.
Best
January 12, 2022 at 5:13 pm #2078589ElvinStaffCustomer SupportNo problem. Let us know how it goes.
-
AuthorPosts
- You must be logged in to reply to this topic.