How to Order Articles in a File Based System

Going back to website basics!

So we are continuing along with our File Based Blog and one apparent issue that crops us is how to arrange the order of the articles when listing them on the main page. There is also the issue on how to only show so many characters of each post (but we have kind of catered for that already).

So what determines any kind of relationship to time, or a set order or even grouping by categories. But one thing at a time.

Well we could either sort by the timestamp, but that has issues if you decide to alter an older article. The only simple but manual way is to create an array which performs the ordering. But this would have to manually maintained? Hmm maybe.

When we scan the folder that stores the articles, the system could take note of it and add it if it is not there already. This would need to occur each time an article was uploaded.

I have just been thinking and as I have finally observed, the current order of the articles is in alphabetical order! Well that is the order they appear in the folder so the function that goes and reads in the file names will or course pull them in the same way.

But what if I got a little more cleverer in my file naming? Hmm, well some of these articles will belong to a series so I could prefix them with something to help group them. I could also add in a step number to help order them. That could work!

So what if I renamed this article file to FBB-1-How-to-order-articles-in-a-file-based-system.php? Or better yet, just to experiment, copy and paste it with the new name and see how it looks. You can do that kind of thing you know!

Coming back to this idea!

Well as I've been bouncing around writing the other articles, I have started using the prefixing system we discussed and it sorts well. But it makes the Links look crappy. So I've got a germ of an idea to pre-process these and effectively hide the prefix when they are displayed on the site.

I'm going to have to leave them in the url for now and I have no idea how that will affect SEO of the site, but time will tell.


Well I have since had a bit of a play with this idea and come up with something strange. The articles as named in their folder are of the format xxx-y-article-name.php, which just so happens to help things sort. So if a group of articles are like abc-1-article-name-1.php and abc-2-article-name-2.php and so on... detecting the abc part helps to group the articles by category (in a very loose sense) and the -1- etc helps to order them. So that is working.

What I have also managed to do is to restructure the links. So instead of the url being abc-1-article-name-1, it's now article-name-1/abc-1 and from the url I can rebuild the filename. I know that all seems a bit silly, but it was an idea to help make things more SEO friendly and it revealed a few nice tricks. Just keep remembering that this is soley a file based system at this stage so I've had to try out some things to help make this easier.