QUICK TIP - WordPress Break Your post to 2 pages with pagination-PHP

0 54,790
pagination | A&H Business Technology
Related posts

WordPress Break Your post to 2 pages with pagination-PHP will support you to custom pagination for your posts. This tutorial will help you to do the task. Your posts will be break into 2 pages depend on your post design.

For example, this tutorial will break the post into 2 page-links. One will show you the Questions and other page-link will reveal the answers.

What is Pagination?

Pagination allows your user to page back and forth through multiple pages of content.

WordPress can use pagination when:

  • Viewing lists of posts when more posts exist than can fit on one page, or
  • Breaking up longer posts by manually by using the following tag.

Using Pagination to Navigate Post Lists Using Pagination to Navigate Post Lists

The most common use for pagination in WordPress sites is to break up long lists of posts into separate pages. Whether you’re viewing a category, archive, or default index page for a blog or site, WordPress only shows 10 posts per page by default. Users can change the number of posts that appear on each page on the Reading screen: Admin > Settings > Reading.

How to the task

The main task of the tutorial will design the pagination your post like image below.

So if you have any of those files in your theme please look at theme first. 

Before we go to next steps, we should know about function.php. If you already know it, please ignore this section and go to next step.

What is : function.php

In WordPress, functions.php or the theme functions file is a template included in WordPress themes. It acts like a plugin for your WordPress site that’s automatically activated with your current theme. The functions.php file uses PHP code to add features or change default features on a WordPress site.

The functions.php file automatically loads when you install and activate a theme on your WordPress site.

Editing the functions.php file using custom codes allows you to add post types, taxonomies, shortcodes, and more to improve your website.

How to implement the code for custom pagination

Put this function in you functions.php

And then go to your theme directory. Search and replace the wp_link_pages function names with the_questions_answer_wp_link_pages. And it’ll work as you wanted. Usually the wp_link_pages exists in content-{template-name}.php.

The function works on odd-even basis. It considers the odd part as ‘Question’ and the even part as ‘Answer’.

Besides, you can adjust its name and codes following your post design such as Exercises and Solutions, Theories and Practices, Pros & Cons  …

And after that you do your styling. Have fun.



TinyURL for this post: https://tinyurl.com/y3ky7btt

Sorry, The Comment Form Is Temporarily Closed At This Time
You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More