0

A search on this topic on this site throws up a lot of results claiming to have resolved this issue, but I am having a contrary experience after implementing these guidelines as outlined here:

  1. How to fix pagination for custom loops?
  2. Pagination not working on static page
  3. https://stackoverflow.com/questions/14026467/pagination-on-static-front-page-wordpress

This is my code below:

                // Get current page and append to custom query parameters array
                $custom_query_args['paged'] = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;

                // Define custom query parameters
                $custom_query_args = array(
                    'post_type'      => 'post',
                    'posts_per_page' => '4',
                    'paged'          => $custom_query_args['paged'],
                    'post_status'    => 'published',
                    'cat'    => '1',
                );

                // Instantiate custom query
                $blog_query = new WP_Query( $custom_query_args );

                // Pagination fix
                $temp_query = $wp_query;
                $wp_query   = NULL;
                $wp_query   = $blog_query;
        ?>

        <?php if ( $blog_query->have_posts() ) : ?>

        <?php /* Start the Loop */ ?>
            <?php while ( $blog_query->have_posts() ) : $blog_query->the_post();  ?>
            <?php get_template_part( 'content', get_post_format() ); ?>

        <?php endwhile; ?>

        <?php endif; // end have_posts() check ?>

        <?php // Reset postdata
            wp_reset_postdata();

            // Custom query loop pagination
            previous_posts_link( 'Older Posts' );
            next_posts_link( 'Newer Posts', $blog_query->max_num_pages );

            // Reset main query object
            $wp_query = NULL;
            $wp_query = $temp_query;
        ?>

When I click on the pagination link displayed on the frontpage, a 404 Not Found response is shown. (The requested URL /kobopulse/page/2/ was not found on this server.)

I am using the latest version of wordpress. On the settings page my install is configured to display a static front page. Front-page.php is my custom page template for the frontpage

What do I need to do differently.

Thanks

Terungwa
  • 171
  • 1
  • 3
  • 14

2 Answers2

0

TO get this solution to work. I simply enabled pretty permalinks. Incase you activate permalinks but you are getting server 404 error, this may imply that the .htaccess is not activated on your server. follow the steps below to get this sorted out.

How to Activate an .htaccess file

If you have access to the server settings you can edit the configuration to allow the .htaccess file to override standard website configs. Open the apache2 default host configuration file. NB: You will need sudo privileges for this step.

sudo nano /etc/apache2/sites-available/default

Once inside that file, find the following section, and change the line that says AllowOverride from None to All. The section should now look like this:

 <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
 </Directory>

After you save and exit that file, restart apache.

sudo service apache2 restart

Make sure this is included in your .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

You are good to go.

reference:

I use an ubuntu server but this reference was useful for me.

http://ahmed.amayem.com/setting-up-pretty-permalinks-in-wordpress-using-htaccess-and-mod_rewrite-on-linux-centos-6/

Terungwa
  • 171
  • 1
  • 3
  • 14
0

I have checked above and seems some issue with your permalink section. Kindly update your permalinks to custom permalinks so it will check seo friendly pagination and you will not get any 404 into it.

Pratik bhatt
  • 1,288
  • 2
  • 13
  • 27