Archived topic
Page/Post Content – How To Show Inside A Tab
3 replies · Started by Pete on January 26, 2022
I'm currently trying to get to grips with the way in which content is hooked/looped through for posts/pages.
For one of my CPTs, the intention is to have three tabs – each displaying different content. The first of these tabs will be open on page load and here I want to be able to show the main post content. The other two tabs will contain content populated by ACFs.
You can see the design on this example.
My problem is the main post content (Biography) isn't hidden when you click another tab. Instead, it remains and forces the other tabs' content to appear beneath it. Is there a way in which this can be achieved.
You can see how the tabs are designed to work here.
Hi Pete,
I’m currently trying to get to grips with the way in which content is hooked/looped through for posts/pages.
The file in charge for this would be this one (single.php) -
https://github.com/tomusborne/generatepress/blob/master/single.php
Particularly, this line:
while ( have_posts() ) :
the_post();
generate_do_template_part( 'single' );
endwhile;
This instruction means "if the post is found, display the post and use 'single' template to display its details".
The line generate_do_template_part( 'single' ); points to this file -
https://github.com/tomusborne/generatepress/blob/master/content-single.php
Which contains the code for the actual template for the single post page's content.
The content part of the page specifically starts and ends on this part -
https://github.com/tomusborne/generatepress/blob/df0190c5f0ac485cb78cb7c2e01365758c4c9d30/content-single.php#L71-L82
With the function the_content() displaying everything you've written as the content of a particular post.
For the tab function, I think that's just a matter of the tabs having the correct scripts function. I've observed your tabs and ideally, it should have an indicator of which tab is the current active tab.
The current tab setup doesn't have this class toggling function.
Thanks Elvin. I can see the looped content isn't the issue here and that it is related to the tab function. Appreciate the impartial eyes on it – will go away and look at that.
No problem. Let us know if you have further questions about this. :D