How to use paginate_links on front-page.php with a custom post type?

The answer depends on what your front page setting is (blog listing or static page) and which query you are trying to paginate (main query or custom query on the template). Because page 2 requests go 404, I assume you’ve set your site to use a static front page and have a custom post type query on the template. In that situation you cannot use the main query’s paged value because the main query only ever consists of one page. You’d need to implement your own paging query var instead of paged.

Instead of doing that, I recommend going back to the blog listing front page setting and altering the main query through “pre_get_posts” action to get your CPT instead of the usual blog posts. Then pagination should work automatically without you having to do anything.

If your front page needs other content than a CPT listing, build it into a custom template named “front-page.php”. The template could for example fetch the content of the current front page and output it before the CPT listing.

If your front page needs other content than a CPT listing, build it into a custom template named “front-page.php”. The template could for example fetch the content of the current front page and output it before the CPT listing.

How can front-page.php include the content of the current front page?

Thank you very very much for the information!



Source link