WordPress custom type admin page markup

So I am creating a plugin that uses custom post types and I want to create a custom layout / interface

I know meta fields, but I believe that this is far from the case.

I am currently using this:

add_action('edit_form_advanced', 'my_add_to_core');

function my_add_to_core() {
    global $post;
    if ($post->post_type == 'my_post_type') {

        $tabs = [
            'General',
            'Settings',
            'Extras'
        ];

        ?>
            <div class="my-container">
                <div class="tab-group">
                    <nav>
                        <ul>
                            <?php $i = 0; foreach ($tabs as $tab) { ?>
                                <?php
                                    $i++;
                                    $title = $tab;
                                    $slug = sf_safestring($tab);
                                    $classes = '';
                                    if ($i == 1) $classes .= 'active';
                                ?>
                                <li class="<?= $classes; ?>"><a href="#<?= $slug; ?>"><?= $title; ?></a></li>
                            <?php } ?>
                        </ul>
                    </nav>
                </div>
                <div class="tabs">
                    <?php $i = 0; foreach ($tabs as $tab) { ?>
                        <?php
                            $i++;
                            $title = $tab;
                            $slug = sf_safestring($tab);
                            $classes = 'tab tab_'.$slug;
                            if ($i == 1) $classes .= ' active';
                        ?>
                        <div class="<?= $classes; ?>">
                            <h3><?= $title; ?></h3>
                        </div>
                    <?php } ?>
                </div>
            </div>
        <?php
    }
}

      

This does what I expect, adding my HTML to the main page layout.

Receives output:

Out putted html

But I believe this is the wrong way to do it. It feels a little hacked.

Anyone have any advice?

+3


source to share


1 answer


Custom Metabots are the right way to customize layouts for custom post types.

Meta boxes are fully supported by Portable Content Groups. They have a lot of pre-designed styles that you can use by simply checking and copying different class names from the main meta fields. End users can also reorganize meta fields if they are not laid out in a way that is convenient to work with. In addition, people can toggle the visibility of each meta field on and off from the dropdown screens. You can also program default locations for each meta field to "start at".

If you want to do something a little faster for development, you can use a framework that is very powerful, popular and commonly used in the WordPress community. It is called ACF or Advanced Custom Fields. It can help you create your own meta fields for a highly accurate CPT workflow.



http://www.advancedcustomfields.com/

I personally don't use it as it might require a big update for all projects using code to update major versions. However, it will shave the days of development off your plate and do some pretty amazing things out of the box.

0


source







All Articles