On a particular archive page I’ve created, I’m listing a number of posts by post name and they’re listed in alphabetical order. Is there away to have them separated even further?
As in all posts starting with “A” are grouped and have a heading of “A”, then all posts starting with “B” are grouped and have a heading of “B”, etc.
You can do some tricky thing with PHP. Here is the algorithm you could use.
for/while
loop starts.$t
= Get first character of the title string.$temp = ''
empty string.if $t != $temp echo $t
.$t = $temp
.endfor/endwhile
.Hope it make sense. The main idea is you check the first character of the title to a temp variable. When their is a mismatch it will print the character. So you will get a character printed out when you transit to
''
toA
,A
toB
and so on.. 🙂Finally got some time. Here is a very basic code example with
get_posts()
This code show the letter if their is an change of first letter of title. Make sure you sort it alphabetically when calling
get_posts()
. Hope you get the idea.