WordPress分页不显示

时间:2018-07-20 05:17:13

标签: php wordpress pagination

我一直在努力获取诸如数字链接之类的分页。当我使用while循环获取帖子但不使用for循环查询的帖子时,分页有效。我在while循环上遇到类别下拉列表的问题,因此我切换到for循环,但是分页停止了工作。需要一些帮助。 我的代码如下: sometemplate.php

        <div class="drop">
    <form id="tool-category-select" class="tool-category-select" action="" method="get">
            <?php wp_dropdown_categories( 'show_count=0&hierarchical=1&exclude=1&show_option_none=Select Category' ); ?>
            <input type="submit" name="submit" value="view" />
        </form>

                    </div>
                    <?php
                wp_reset_query();
                $post_tag = 'futura';
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $offset = ( $paged - 1 );
                $args = array( 'post_type' => 'post', 'posts_per_page' => 12,'tag'=> $post_tag,'paged' => $paged, 'offset' => $offset, 'taxonomy' => 'category', 'category' => $_GET['cat'], 'max_num_pages' => '50'); //get all posts );




                $myposts = get_posts( $args );
                    foreach ( $myposts as $post ) : 
                      setup_postdata( $post ); ?>
                   <div class="prod_item">
                            <a href="<?php the_permalink(); ?>">
                                <span class="title"><?php the_title(); 
                                ?></span>
                                <?php the_post_thumbnail( 'prod_thumb' ); ?>
                                <span class="know_more">KNOW MORE<i class="fa fa-angle-right"></i></span>
                            </a>

                        </div>
                    <?php 
           endforeach;

        if (function_exists("pagination")) {
                          pagination($custom_query->max_num_pages);
                      }




                    wp_reset_query();?>

                    <?php


                ?>

function.php

function pagination($pages = '', $range = 4)
        {
        $showitems = ($range * 2)+1;

        global $paged;
        if(empty($paged)) $paged = 1;

        if($pages == '')
        {
        global $wp_query;
        $pages = $wp_query->max_num_pages;
        if(!$pages)
        {
        $pages = 1;
        }
        }

        if(1 != $pages)
        {
        echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
        if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
        if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

        for ($i=1; $i <= $pages; $i++)
        {
        if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
        {
        echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
        }
        }

        if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
        if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
        echo "</div>\n";
        }
        }

0 个答案:

没有答案