分页的分页

时间:2012-10-16 10:17:51

标签: jquery jquery-plugins jquery-cycle

我正在尝试构建一个非典型的循环导航。

通常它会像这样建立......

<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">7</a>

我想做的是将每两个元素包装在另一个div中,如下所示:

<div class="wrap">
   <a href="#">1</a>
   <a href="#">2</a>
</div>
<div class="wrap">
   <a href="#">3</a>
   <a href="#">4</a>
</div>
<div class="wrap">
   <a href="#">5</a>
   <a href="#">6</a>
</div>
<div class="wrap">
   <a href="#">7</a>
</div>

我知道,我应该使用

pagerAnchorBuilder

但不知道aho将事情包装在一起。 任何人都知道如何正确地做到这一点?

2 个答案:

答案 0 :(得分:3)

您可以使用简单的循环和slice()

来完成此操作
var $anchors = $('a');
for (var i=0; i < $anchors.length; i+=2) {
  $anchors.slice(i, i+2).wrapAll('<div class="wrap" />');
}

哪会给你:

<div class="wrap">
   <a href="#">1</a>
   <a href="#">2</a>
</div>
<div class="wrap">
   <a href="#">3</a>
   <a href="#">4</a>
</div>
<div class="wrap">
   <a href="#">5</a>
   <a href="#">6</a>
</div>
<div class="wrap">
   <a href="#">7</a>
</div>

Here's a fiddle

答案 1 :(得分:-2)

/ * --------------------------------------------- ------------------------  * Paggenation对于这个网站。   ----------------------------------------------- ---------------------- /

function geigerakademie_posts_paginate($ args = false){

        $type = 'posts';
        $options = array();
        $previouspage = '&laquo;';
        $nextpage = '&raquo;';
        $before = '<div class="paging clearfix">';
        $after = '</div>';
        $range = 3;
        $title = '';
        $anchor = 1;
        $gap = 1;

        $r = wp_parse_args($args, $options);
        extract($r, EXTR_SKIP);

        if (!isset($page) && !isset($pages)) {
            global $wp_query;

            if ($type === 'posts') {
                $page = get_query_var('paged');
                $posts_per_page = intval(get_query_var('posts_per_page'));
                $pages = intval(ceil($wp_query->found_posts / $posts_per_page));
            }
            else {
                $page = get_query_var('cpage');
                $comments_per_page = get_option('comments_per_page');
                $pages = get_comment_pages_count();
            }
            $page = !empty($page) ? intval($page) : 1;
        }

        $prevlink = ($type === 'posts')
            ? esc_url(get_pagenum_link($page - 1))
            : get_comments_pagenum_link($page - 1);
        $nextlink = ($type === 'posts')
            ? esc_url(get_pagenum_link($page + 1))
            : get_comments_pagenum_link($page + 1);

        $output = stripslashes($before);
        if ($pages > 1) {

            $ellipsis = "<a class='gap'>...</a>";

            if ($page > 1 && !empty($previouspage)) {
                $output .= sprintf('<a class="page-prev" href="%s"><span> </span></a>', $prevlink);
            }

            $min_links = $range * 2 + 1;
            $block_min = min($page - $range, $pages - $min_links);
            $block_high = max($page + $range, $min_links);
            $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
            $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;

            if ($left_gap && !$right_gap) {
                $output .= sprintf('%s%s%s',
                    geigerakademie_posts_paginate_loop(1, $anchor),
                    $ellipsis,
                    geigerakademie_posts_paginate_loop($block_min, $pages, $page)
                );
            }
            else if ($left_gap && $right_gap) {
                $output .= sprintf('%s%s%s%s%s',
                    geigerakademie_posts_paginate_loop(1, $anchor),
                    $ellipsis,
                    geigerakademie_posts_paginate_loop($block_min, $block_high, $page),
                    $ellipsis,
                    geigerakademie_posts_paginate_loop(($pages - $anchor + 1), $pages)
                );
            }
            else if ($right_gap && !$left_gap) {
                $output .= sprintf('%s%s%s',
                    geigerakademie_posts_paginate_loop(1, $block_high, $page),
                    $ellipsis,
                    geigerakademie_posts_paginate_loop(($pages - $anchor + 1), $pages)
                );
            }
            else {
                $output .= geigerakademie_posts_paginate_loop(1, $pages, $page);
            }

            if ($page < $pages && !empty($nextpage)) {
                $output .= sprintf('<a class="page-next" href="%s"><span> </span></a>', $nextlink);

            }
            $output .= "</ol>";
        }
        $output .= stripslashes($after);

        if ($pages > 1 || $empty) {
            echo $output;
        }
    }

function geigerakademie_posts_paginate_loop($ start,$ max,$ page = 0){

        $type = 'posts';

        $output = "";
        for ($i = $start; $i <= $max; $i++) {
            $p = ($type === 'posts') ? esc_url(get_pagenum_link($i)) : get_comments_pagenum_link($i);
            $output .= ($page == intval($i))
                ? "<a class='page current' href='javascript:void(0)'>$i</a></span>"
                : "<a href='$p' title='$i' class='page'>$i</a>";
        }
        return $output;
    }