phpwordpresscontent-management-systemaccordion

How to add an editable accordion in WordPress


I am trying to add an accordion to a page in WordPress.

The issue being, I need the accordion to be editable from the CMS, and if possible, a user could add the accordion on different posts.

I have looked into it, and found that Advanced Custom Fields Repeater might be the way to go, but yet to find a good read on how to implement this.

Any help would be great.


Solution

  • I use Advanced Custom Fields Repeater for something very similar, and it does give my users the ability to enter content that can be repeated. This is valuable because you can wrap each part in html and then the whole thing can be wrapped, which would let you do your accordion.

    Here is the repeater code, mine is for events.

    if (get_field('monthly_events')){
        $events = get_field('monthly_events'); 
    
        foreach($events as $event) {
            ?>
            <li>
                <strong><?php echo $event['event_name']; ?></strong>
                <p><?php echo $event['event_description']; ?></p>
            </li>
            <?php
        }
    }
    

    You should read their instructions. You have to create and name your fields using their interface, apply it to a new post type, and then put your accordion html into a new template for that post type. It's not rocket science but there are many steps so read their instructions. http://www.advancedcustomfields.com/add-ons/repeater-field/