One thing I’d like to add to the conversation,
Please note that PHP is independent / unrelated to WordPress. It’s the language that was chosen to build WordPress, but it could have been another language (Ruby, Python, etc).
So yes, it’s absolutely possible to use PHP outside of the WordPress platform. PHP has helped built websites like Facebook, Yahoo, Wikipedia, Tumblr, Flickr, as well as WordPress.
To run PHP, you basically just need a text editor to write it (VSCode, Atom, Sublime…) and a webserver to run it, as Stetim mentioned. You can run it on localhost if you set up a webserver on your machine, or download an out-of-the-box solution such as XAMPP. Which is super easy to set up and use.
To do what you want to do, you’ll need a database. So you need to get familiar with this.
Within your database, you’ll have tables.
One table will be the “posts” table.
In your posts table, you’ll have columns.
For example, the columns could be
id | title | body | count
count, you’d store the number of times the post has been read.
Every post has its own row, like:
1 | My first post | Hey guys, this is my first | 12
2 | My second post | Hey, back for another one | 24
Every time someone reads the post, just send the information to the database (increase the total of
count by 1). Then, to get your three most popular posts, just select the ones that have the highest numbers in the
This you’ll need to do with another language, called SQL.
It’d look something like
SELECT title FROM posts ORDER BY count DESC LIMIT 3
This would give you the three most popular posts, starting with the one having the highest count (so, from our fake database, “My second post” would appear before “My first post”).
Hope this is helpful and not too confusing… I’ve given you an idea on how to do this, but you’ll still need to figure out how to send the information to the database, increase the count, etc. as well as how to set up your database, tables, columns, and all. Might be overwhelming, but you’ll learn a great deal.
Best of luck!