简体   繁体   中英

My pagination doesnt work in wordpress custom theme

I am using pagination_bar from function.php. I implemented that in custom page called page-blog.php. I restriced pages to only 2 per page and i have 3 blog posts. After I put pagination_bar() function it shows me fatal error.

I saw some soluton already here but none of them helps. I have tried doing some offset.

function.php

function pagination_bar() {
    global $wp_query;

    $total_pages = $wp_query->max_num_pages;

    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => 'page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text' => '<i class="fa fa-angle-left"></i>',
            'next_text' => '<i class="fa fa-angle-right"></i>'
        ));
    }
}

page-blog.php

             <div class="col-xl-8 col-md-12 col-lg-8 col-sm-12 col-xs-12 md-blog-posts">

                        <?php 

                            $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;


                            $homePagePosts = new WP_Query(array(
                                'posts_per_page' => '2',
                                'post_type'   => 'post',
                                'has_archive' =>  true,
                                'post_status' =>  'publish',
                                'order'       =>  'DESC',
                                'paged' => $paged,


                            ));
                        if($homePagePosts->have_posts()) :
                            while($homePagePosts->have_posts()) :
                            $homePagePosts->the_post(); ?>
                            <div class="col-xs-12 col-md-12 col-lg-12 md-blog-blog">
                                <div class="md-blog-img">
                                        <div class="img-container">
                                            <div class="positioning">
                                                <span class="md-blogdate-number"><?php the_time('F d, Y.'); ?></span>
                                                <h4 class="md-blog-title"><?php echo get_the_title() ?></h4>
                                                <a href="<?php the_permalink(); ?>" class="btn md-button-read-more" id="md-blog-button">Read More</a> 
                                            </div>
                                            <div class="md-blog-img"><?php  the_post_thumbnail() ?></div>
                                    </div>
                                </div>
                            </div>
                            <?php endwhile;  ?>


                         <?php else : ?>

                            <h1>There is no posts at this moment</h1>

                         <?php endif; ?>

                         <div class="md-pagination-holder" style="background: #333; width:50px; height: 50px; color: #fff;">            
                            <?php paginate_bar(); ?>
                        </div>
                </div>

Also you can see the website here - > http://prodenvermovers.wpupkeep.org/blog/

I get fatal error.

EDIT : http://prntscr.com/oij1dr

I chaned paginate_bar to pagination_bar as function is actually called but i get error above when i refresh the page.

Try this to see if you can get the page to work. In this example it just uses the built in WP hooks to generate pagination links. Also, by "still not working" do you mean you are still getting the error, or just not seeing the pagination?

             <div class="col-xl-8 col-md-12 col-lg-8 col-sm-12 col-xs-12 md-blog-posts">

                        <?php 

                            $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;


                            $homePagePosts = new WP_Query(array(
                                'posts_per_page' => '2',
                                'post_type'   => 'post',
                                'has_archive' =>  true,
                                'post_status' =>  'publish',
                                'order'       =>  'DESC',
                                'paged' => $paged,


                            ));
                        if($homePagePosts->have_posts()) :
                            while($homePagePosts->have_posts()) :
                            $homePagePosts->the_post(); ?>
                            <div class="col-xs-12 col-md-12 col-lg-12 md-blog-blog">
                                <div class="md-blog-img">
                                        <div class="img-container">
                                            <div class="positioning">
                                                <span class="md-blogdate-number"><?php the_time('F d, Y.'); ?></span>
                                                <h4 class="md-blog-title"><?php echo get_the_title() ?></h4>
                                                <a href="<?php the_permalink(); ?>" class="btn md-button-read-more" id="md-blog-button">Read More</a> 
                                            </div>
                                            <div class="md-blog-img"><?php  the_post_thumbnail() ?></div>
                                    </div>
                                </div>
                            </div>
                            <?php endwhile;  ?>
                               <div class="nav-previous alignleft"><?php previous_posts_link( 'Older posts' ); ?></div>

                               <div class="nav-next alignright"><?php next_posts_link( 'Newer posts' ); ?></div>

                         <?php else : ?>

                            <h1>There is no posts at this moment</h1>

                         <?php endif; ?>


                </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM