Thanks for taking an intrest
I am looking for some to provide a clear, good practice, example (or link to an existing one) of how to create an A to Z list of posts with Pagination for Custom Post Type in the latest version of WordPress based on the scenario below.
There are two existing questions I have found on this site but neither answer the question clearly or definitively.
To keep things simple for me to explain the scenario and for those responding. I am basing my explanation around a website all about Fruit. When trying to use the answers given I am hoping this will be easy for I and other learners to follow the replys and intergrate it into their own code.
Basic Structure
- I have created a Custom Post Type called “Fruits“.
- I have created a series of Posts within Fruits, each with a Post Title
of a particular fruit e.g. “Bananas”. - I have created a Page Template within which is the following div:
<div id="MyAtoZArea" class="MyAtoZStyle"></div>
.
Output
- Within the div I would like code that will display a list of all the
posts in the custom post type “Fruits”. - I would like to wrap the output in an unordered list
<ul>
with each title being a different list item<li>
- I would like the list to be sorted alphabetically by the Post Title.
- As each letter of the Alphabet changes I would like it to be inserted. For example:
A
Apples
Apricots
B
Bananas
- I would like for letters of the alphabet not to be shown if there are no applicable posts. For example:
A
Apples
K
Kiwi
S
Strawberrys
- Finally I would like to show a maximum of 20 posts, using pagination to show the next 20 and so on.
Can you help? If so post below.
All constructive guidance and comments are welcome.
I would do it like below. The following code you should post in your template:
You could easyly alter your code to also display labels for letters without posts
Please use this below code. The following code you should use in your post type template: it’s really work for me… I have also tested this code…. See screenshots 1. http://prntscr.com/dxzi22 (full A to Z) 2. http://prntscr.com/dxziih (Full A to Z with Pagination)… you need do to some CSS for that…