wordpress拖放后元框页面生成器

时间:2016-10-27 04:51:03

标签: wordpress drag-and-drop post-meta

我很累,尝试为我的免费源代码添加自定义选项以进行拖放。

你们中的任何人都可以帮我将自定义选项添加到此代码中。

add_action('admin_enqueue_scripts','enqueue_related_pages_scripts_and_styles');

    //defines the output for our related pages meta box
    function display_related_pages_meta_box($post){
        //create nonce
    wp_nonce_field('pages_meta_box','pages_meta_box_nonce');

    //collect related pages (if we already have some)
    $related_pages = get_post_meta($post->ID,'related_pages',true);

    //collect all pages on the website
    $page_args = array(
            'posts_per_page'    => -1,
            'post_type'         => 'page',
            'post_status'       => 'publish',
            'orderby'           => 'post_date',
            'order'             => 'DESC',
            'fields'            => 'ids'
        );
    $pages = get_posts($page_args);
    //if we have pages to display
    if($pages){
        echo '<div class="related_pages">';
            //left container (all pages)
            echo '<div class="left_container">';
                echo '<p> Listed below are the pages of your website.</p>';
                echo '<p>Drag these to the other container to add them as related page links </p>';
                //loop through all pages
                foreach($pages as $page){
                    //collect their id and name and create the page item
                    $page_id = $page;
                    $page_name = get_the_title($page_id);
                    echo '<div class="page_item" data-page-id="' . $page_id . '">';
                    echo    '<div class="page_title">' . $page_name . '</div>';
                    echo    '<div class="remove_item"> Remove </div>';
                    echo '</div>';
                }
            echo '</div>';
            //end left container

            //Right container
    echo '<div class="right_container">';
    echo    '<p>Drag pages from the left container onto this container </p>';
    //if we have previous saved related pages
    if(!empty($related_pages)){
        $related_pages_array = json_decode($related_pages);
        foreach($related_pages_array as $related_page){
            //page information
            $page_id = $related_page;
            $page_name = get_the_title($page_id);

            echo '<div class="page_item" data-page-id="' . $page_id . '">';
            echo    '<div class="page_title">' . $page_name . '</div>';
            echo    '<div class="remove_item active"> Remove </div>';
            echo    '<input type="hidden" name="related_pages[]" value="' . $page_id . '"/>';
            echo '</div>';
        }
    }
    echo    '<div class="droppable-helper"></div>';
    echo '</div>';
        echo '<div class="clearfix"></div>';
        echo '</div>';
    }
    }

此代码取自网络。我想知道如何为此添加自定义选项,而不是使用上面给定代码中的查询的默认选项。

0 个答案:

没有答案