WordPress分页 - 不工作 - 自定义插件

时间:2014-02-03 16:58:00

标签: php wordpress pagination

所以我目前正在开发一个依赖于自定义帖子类型的自定义插件。然后我在管理页面中显示这些自定义帖子类型,但似乎无法显示分页!我不知道我做错了什么。

这是我正在运行的循环:

<?php
        if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }

        $mypost = array( 'posts_per_page' =>'1','paged'=>$paged,'post_type' => 'usernotes', 'meta_query' => array(
                array(
                    'key' => 'userNotesID',
                    'value' => get_current_user_id( )
                )
    ));
        $loop = new WP_Query( $mypost );
    ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post();?>
    <section class="innerWrapper">
            <article id="<?php the_ID(); ?>" class="note" <?php post_class(); ?>>
            <header class="entry-header">
                        <!-- Display Title and Author Name -->
                        <span class="title"><?php the_title(); ?></span>
                        <span class="date"><?php the_time(get_option('date_format')); ?></span>  
                </header>

                <div class="noteInner">
                    <?php the_content(); ?>
                </div>

                <footer>
                    <a href="'#" class="delete button-red" id="<?php the_ID(); ?>">Hide Note</a>
                    <div class="clear"></div>
                </footer>
            </article>
</section>


    <?php endwhile; ?>

它显示1个帖子,如果我将posts_per_page增加到2那么它应该显示2个帖子。问题是我无法获得任何分页链接。如果我将它设置为1,然后导航到?paged = 2,没有任何变化,它只显示第一个帖子!知道为什么或我能尝试什么?

编辑:

应该可以在管理页面上添加它,显示自定义帖子类型。

1 个答案:

答案 0 :(得分:0)

如何使用&#39; current&#39;您的查询中的属性?如

'current' => max( 1, get_query_var('paged') )

我忘记了我在哪里找到这个功能,但它在我的几个项目中没有任何问题。它使得阅读和编辑也变得更加容易。

if ( ! function_exists( 'my_pagination' ) ) :
    function my_pagination($wp_query) {

        $big = 999999999; // need an unlikely integer

        echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'total' => $wp_query->max_num_pages,
            'prev_text'    => __('<'),
            'next_text'    => __('>'),
            'type'         => 'plain',
        ) );
    }
endif;    

我希望这会有所帮助。