You may well be aware that a WordPress blog, such as the one you are viewing, has a MySql database which is like its signature … well, more than a signature … basically most of its identity, because no matter what styling and theming you apply (and in any case some of the styling and theming ideas get stored in the database as well) the data behind the blog is what makes it what it is.
The WordPress PHP software has a “Fred and Ginger” relationship with its MySql database. Who’s Fred, and who’s Ginger? … leave that for you.
But as with most decent dances you used to be able to tap somebody on the shoulder and ask for a changed arrangement … are you all rolling around on the floor yet? … the older of us have gone to the fridge to get a banana muffin I expect?!
Anyway, to cut a long story short, we are going to separate ourselves from WordPress PHP, and write our own, that sits outside and makes changes to the WordPress blog by adjusting the WordPress blog’s MySql database from this removed position. Okay, if you want to be dramatic … “in a backdoor way”. And what do you need to do this?
- MySql hostname
- MySql username
- MySql password
- MySql database name
… in order to make a connection to the MySql database from PHP. This word “connection” is absolutely massive in the Information Technology world, because the Information Technology world is increasingly about networking and devices and synchronicity and data and databases and services, but bear in mind (all) this networking was once a secretive and arcane “art”, so things have come along/”a long way” (chortle, chortle). Wonder what the sky would look like if every message we sent via a connection had a unique streaky air-dye colour as it streaked through the atmosphere?
Okay, for the point of today’s mission … we want to end up with a comma delimited list of blog posting ID numbers that all belong to a category of interest (and that are more than 8 days old … thanks).
That last bit probably gives the game away, but, nevertheless we’ll leave it until tomorrow to let you know how this functionality could be of use.
By the way, if you were within WordPress PHP code you could use the “get_posts()” functionality to achieve this as well, I think.
There is, what seems to me, a logical approach to achieving this …
- create a piece of SQL (an example of which we’ve saved for your perusal you could call software_posts.sql) that will get those ID numbers of a particular category older than 8 days, and for great help here would like to thank this very useful link from WordPress.org support forum (thanks) … in order to achieve this we use the incredible, the marvellous, the witty (you had to be there), the curiously refreshing “phpMyAdmin” … read more here
- take another piece of PHP that did something like what we want to do today … do you remember tutorial_options.php (from here)? … and plug in the SQL and modify the rest to end up with category_software_list.php … store the results in a file you can see at software_posts_list.php
So we hope to see you back here tomorrow to complete the loop, and in the meantime you might like to review today’s tutorial.
If this was interesting you may be interested in this too.
3 Responses to WordPress Blog Category List Primer Tutorial