Skip Navigation

[Resolved] WordPress Archive Alphabetical Pagination

This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by Nigel 7 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#465641
Untitled.jpg

I am trying to have the WordPress Archive display with an Alphabetical Pagination.

Currently I have the wordpress Archive display in alphabetical order but the pagination is numerical. My customer wants a way to move around alphabetically.

#465810

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

alpha.gif

Hi Gilad

There isn't an option to filter the archive alphabetically but you can set something up to simulate it without too much trouble.

See the screen recording to see it in action.

Here's what you need.

You need to create a taxonomy called, say, alphabet, where each of the terms is just a letter (so you will add 26 terms).

Assign this taxonomy to your post type.

Now, you will need to edit (or quick edit) your posts and add the alphabet term (aka the letter) for that post.

That does require manual intervention, but it does mean that you can choose to show, for example, The Big Lebowski under 'B' rather than 'T'.

When you have done this, create a taxonomy view called, say, alphabet terms.

This will display your alphabet taxonomy terms.

One setting to think about is "don't show empty terms", i.e. whether to show letters for which there are no posts.

Order by term name ascending (to display your letters as the alphabet).

Then in the loop output editor simply add [wpv-taxonomy-link].

So the letters will render on the screen and be a link to the archive for that letter, i.e. the 'B' taxonomy archive will show all posts beginning with 'B' (or, rather, which you have assigned the alphabet term 'B' to).

Then edit your WordPress archive and insert the alphabet terms view before the loop output to display the alphabetic links.

On my test site the loop output for the post archive looks like this:

[wpv-layout-start]
[wpv-view name="alphabet-terms"]
[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          <h3>[wpv-post-link]</h3>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

One more extra step is that you may need to create a custom taxonomy term archive for the alphabet taxonomy to match your post archive, where you will also need to insert the alphabet terms view before the loop output to display the alphabet. (If you don't do this last step then when you come to test it you should see what I mean.)

#467250

Thank you Nigel,

I will try to implement this technique.

I will update you with my progress.

Gilad

#467259

Nigel,

I had success implementing your workaround. However what I need is to be able to have the alphabetical pagination list only the posts within the taxonomy archive category that is being viewed.

I am building a Pilot Wings database. Users can now select to view wings based on "Wings Category" taxonomy which has many subcategories. For now if a user choses to view the wings under the commercial wings -> USA subcategory the archive displays all the wings within that subcategory. However the alphabetical pagination I built using your method will show all the wings, not just those of the subcategory.
I essentially need to be able to display only the wings (posts) that fall into the subcategory selected and the "Alphabet" taxonomy.

I hope i'm making some sense of this. Pleases feel free to visit the site:

hidden link

Navigate to commercial wings and choose USA. You will see all the wings in the Commercial/USA subcategory. What i'm trying to do is sort only those wings in a alphabetical pagination.

Appreciate the help,

Gilad

"The dude abides..."

#467476

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screen Shot 2016-12-14 at 14.16.10.png
genre-tax.gif

Hi Gilad.

That makes things somewhat more complicated. The current solution works by going to an alphabet taxonomy archive when you select a letter, but you are coming from—and want to stay on—a different taxonomy archive (the USA sub-category, for example).

I re-worked this in my test site and got it working, although it took a little doing, and required me to register a custom shortcode which I'll describe below.

You can see the results in the revised screen recording, where I am on a film genre archive, and stay on it as I use the letter 'filters'.

So, we still have the alphabet taxonomy which you need to assign to your posts.

We need to modify the alphabet terms view that generates the alphabet filters, because we don't want the links to go to the alphabet taxonomy archive anymore, we want to stay on the (in the case of my test site) genre taxonomy archive, but add an additional query filter for the alphabet term. We'll pass the alphabet term (the letter) using a url parameter.

(So, in my screen recording I am initially on the drama genre archive, and once I click a letter I stay on the same page but am additionally filtering by the alphabet archive.)

So the loop output section of my alphabet view now looks like this:

[wpv-layout-start]
	[wpv-items-found]
	<a href="[current_url]">All</a>
	<!-- wpv-loop-start -->
		<wpv-loop>
			<a href="[wpv-post-taxonomy type='genre' format='url']?wpvalphabet=[wpv-taxonomy-title]">[wpv-taxonomy-title]</a>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

You'll note that I added a link to "All", to not filter by any letter, which is where I resorted to a custom shortcode, but I'll come back to that at the end.

The key change is in what's inside the wpv-loop tags. Now I am manually building the link, which will keep me on the same page, but which adds the letter as a url parameter 'wpvalphabet'.

Because of how I had this set up before I didn't have a custom archive for the genre taxonomy, so I needed to go ahead and create that now. That is what lists the matching films when I visit a url such as mysite.com/genre/drama.

Now I add a Query Filter to this archive which is a Taxonomy filter for the alphabet taxonomy where the value is set by the url parameter wpvalphabet (see screenshot).

In the output section I need to add my alphabet terms view before the wpv-loop tags, like so:

[wpv-layout-start]
	[wpv-items-found]
	[wpv-view name="alphabet-terms"]
	<!-- wpv-loop-start -->
		<wpv-loop>
          <h3>[wpv-post-link]</h3>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

The result is as per my screen recording.

A tricky part was the url for the 'All' link, for which I wrote a small custom shortcode that outputs the current url minus any url parameters. You'll need to add the following to your functions.php file or using a plugin such as Code Snippets.

/**
 * Register custom shortcode to output url of current page
 * Minus any url parameters
 */
add_shortcode( 'current_url', function(){

	$request = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"],'?');
	$protocol = '<em><u>hidden link</u></em>';

	if ( $_SERVER['HTTPS'] ) {
		$protocol = '<em><u>hidden link</u></em>';
	}

	return $protocol . $request;
} );

There is quite a lot to digest there, but you should have everything you need to implement it on your own site.

Good luck!

#467698

Nigel,

Thank you so much!

Your solution worked well, and was relatively easy to implement.
I even ended up using it in a custom search result.

Since I seem to have found a particularly good support person in you I was wondering if I could tag on one more question.

I want to implement a next and previous post button on my post page (in my case my individual wing page). I found a way to do this on some online forums, however the problem is that the buttons take you to some random other post. I would like the next and previous post buttons to take you to the next or previous post within the same taxonomy category, and preferably in alphabetical order.

Any suggestions?

Again thanks for all your help.

Gilad

#467710

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Gilad

We have a one issue per thread policy as it helps other users researching similar issues, so could I ask you to open a new thread?

Now that you have a resolved thread by me you are able—and welcome—to assign the new ticket to me.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.