首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在wordpress中保存jquery可排序顺序

如何在wordpress中保存jquery可排序顺序
EN

Stack Overflow用户
提问于 2013-11-08 06:55:52
回答 1查看 2.8K关注 0票数 1

我使用了jquery sortable,它的工作非常完美。但这不能拯救他们的秩序,我怎样才能拯救它?

这里的任何一个帮助都是我的代码

代码语言:javascript
复制
<?php
add_action('wp_enqueue_script','image_sort');       
function image_sort(){  
    wp_enqueue_script( 'jquery-ui-sortable' );  
    }
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
   $('table#image_sort tbody').sortable();
});

</script>
<?php if(!empty($wp_logo_slider_images)) : ?>   
<table class="widefat fixed" cellspacing="0" id="image_sort">
    <thead>
        <tr>
            <th scope="col" class="column-slug">Image</th>
            <th scope="col">Image Links To</th>
            <th scope="col" class="column-slug">Actions</th>
        </tr>
    </thead>
         <tbody>
            <tr>
                <td>1</td>
                <td>2</td>
                <td>3</td>
             </tr>
    </tbody>
</table>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-14 13:33:53

首先在文件中正确调用jQuery库,然后将值保存在wp_options中。

代码语言:javascript
复制
function image_sort(){  
wp_enqueue_script('jquery');
?>
<!--<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>-->
<?php 
wp_enqueue_script('jquery-ui-sortable');
?>
<script type="text/javascript">

jQuery(document).ready( function(e) {
   jQuery('#image_sort').sortable({
            items: '.list_item',
            opacity: 0.5,
            cursor: 'pointer',
            axis: 'y',
            update: function() {
                var ordr = jQuery(this).sortable('serialize') + '&action=list_update_order';
                jQuery.post(ajaxurl, ordr, function(response){
                    //alert(response);
                });
            }
      });
});

</script>
<?php
    }
    add_action('admin_head','image_sort');

function order_list(){
        global $wp_logo_slider_images;

        $list = $wp_logo_slider_images;
        $new_order = $_POST['list_item'];
        $new_list = array();

        foreach($new_order as $v){
            if(isset($list[$v])){
                $new_list[$v] = $list[$v];
            }
        }
        update_option('wp_logo_slider_images',$new_list);
    }
    add_action('wp_ajax_list_update_order','order_list');

<table class="widefat fixed" cellspacing="0" id="image_sort" style="width:100%; table-layout:inherit;">
     <tr id="list_item_<?php echo $image ?>" class="list_item">
         Your Values
     </tr>
</table>

希望你能找到答案

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19853250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档