Question

I have a plain HTML website with WP in a subfolder (/blog). I need to display latest posts from /blog into the plain HTML webpage.

Is there a PHP script or some kind of widget to achieve this?

Thanks!

Was it helpful?

Solution

Perhaps you could consider using WP REST API to get the posts with a XMLHttpRequest in javascript instead of trying to get php work on .html file(s).

From the REST handbook,

The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects.

And

It provides data access to the content of your site, and implements the same authentication restrictions — content that is public on your site is generally publicly accessible via the REST API, while private content, password-protected content, internal users, custom post types, and metadata is only available with authentication or if you specifically set it to be so.

OTHER TIPS

1) Run php code in html files

You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to. To do this you need to create a .htaccess file in your root web directory and add this line to it:

AddType application/x-httpd-php .htm .html

This will tell Apache to process files with a .htm or .html file extension as PHP files.
(related answer)

2) Use Wordpress functionality outside of wordpress folder

If you able to use php in your html files, you need to include wordpress wp-load.php file to load wordpress functionality. I'm not familiar with your folders' structure, so you will need to modify a path to this file by yourself.

require_once( '../blog/wp-load.php' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top