What am I looking at?

This is a Construct 3 WebApp that is connecting to a WordPress plugin at twistedvoid.com which is selecting posts in the C3 News category, getting specific details of the post llike title, author, content and wrapping it all in a JSON response to send back to the C3 app.

The C3 app then parses the JSON, grabs the keys and values and pastes them into this HTMLElement.

The beauty of this is, once you have the CSS set up for the HTMLElement, all you have to do is create a new post in WordPress and the plugin feeds it to the C3 app when it requests it.

If you click this link: https://twistedvoid.com/blog/2023/01/19/what-am-i-looking-at/, you can see the actual WordPress post that this was taken from.

What this also means is, that you can post your game news on your WordPress website and have it automatically appear in your game!

And it’s flexible!

AJAX requests are used to fetch the news from the website. The plugin then returns all posts in a specific category. Seven ‘fields’ are returned in the JSON.

  • post_title – The title of the post.
  • post_content – The full content of the post.
  • post_excerpt – A short excerpt of the post if it’s enabled in WordPress
  • post_author – Author of the post. This can be either the actual login name or nickname of the author.
  • post_time – Time the post was created. This can easily be change in WordPress when the post is created.
  • post_gm_time – Post GMT. The actual GMT of when the post was created.
  • post_link – A HTTP link back to the post. This allows you to create a ‘read more’ link when using excerpts.

Processing the JSON in C3 is a couple of loops where each post is looped through and then each of the above keys is looped through. In the example below, each key’s value is assigned to a local function variable. After the keys and values of the post are found, HTMLElement.Insert is used to place each one in the HTMLElement in the order desired.

Adding images in posts works as well. Click the image.

Ok, fine. I like it but… what else can it do?

Because this is an AJAX requests to a WordPress plugin, the plugin can also track other data. Like:

  • IP address of the app.
  • The Remote Host.
  • Whether the request came through the TOR network.
  • The User Agent
  • The Referrer
  • The time and date of the request.

All of this data is stuffed into a MySQL database which you can then use to track various statistics about your game, like how many users per day are using your app, which days of the week are the most popular or, combining it with GeoIP data what countries is my app being most used in.

Other features?

  • Choose which WordPress category you want to show in the news.
  • Posts returned to the C3 app are sorted by date with the most recent at the top.
  • Limit the number of posts that are sent back to the C3 app. This means you can write as many news items as you like but the C3 app will only see the first 5, 10, 20, etc.

You can also control the CORS origin (Cross-Origin Resource Sharing). The website where these news articles is coming from is set to allow requests from anywhere. It uses this in the header:

Access-Control-Allow-Origin: *

This means that anyone, anywhere can request news from the WordPress site. You can also change the CORS header to allow news requests only from your site. If you’re only running a web-based app, you can change the CORS header to something like this:

Access-Control-Allow-Origin: http://www.example.com