I am using Bootstrap with WordPress and I want to implement the collapse functionality in the content for single pages of a specific custom post type.
I know I could create a shortcode, however, with hundereds of posts shortcodes are not going to be ideal. Is it possible to include collapse in the_content of the custom post type (custom-single.php). So when a user enters an .H2 with text below it .p it uses this for a collapse group.
So in the custom-single.php I wrap the_content in a custom div id
<div id="my-accordion"><?php the_content(); ?></div>
How I can associate the H2 and p with appropriate div classes for bootstrap. Is this possible?
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
Collapsible Group Item #1
</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
Anim pariatur cliche...
</div>
</div>
</div>
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
Collapsible Group Item #2
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
Anim pariatur cliche...
</div>
</div>
</div>
</div>
The script
First you have to enqueue the script. We conditionally load it only for your custom post type and its archive(s).
The MarkUp
Now we need to add the proper MarkUp. The targets get marked by using the actual
the_ID()
of the currently looped post.From the Codex you can wrap your post title in before and after elements. So … I think you would cut out / change your
POST TITLE’