Skip to content
A simple Vue blog template that displays posts from any WordPress REST API endpoint.
Vue CSS JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
public
src
.env.sample Load endpoint and analytics ID from environment variables. Jul 26, 2019
.eslintrc Add Prettier setup. May 17, 2019
.gitignore
.nvmrc
.prettierignore
.travis.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
babel.config.js
netlify.toml
package-lock.json
package.json
vue.config.js

README.md

WP Vue

Build Status Netlify Status

This is just a simple Vue application (scaffolded using the Vue CLI) that pulls posts from a WordPress REST API endpoint. Clone or fork this sucka & rip it apart to suit your own needs. If you have ideas to make it better for everyone else, contribute!

Install

In the root of the project, run npm install.

Usage

Set Your Environment Variables

Various important values are loaded into the application via Node environment variables, which you'll need to define. Locally, run cp .env.sample .env.local to create a local file for defining the following:

  • REST_ENDPOINT - The WordPress REST API endpoint from which data will be pulled. Leave off the trailing slash. Example: https://blah-blah-blah.com/wp-json/wp/v2
  • POSTS_PER_PAGE - The default number of posts per page that will be displayed.
  • GA_TRACKING_ID - A Google Analytics tracking ID.
  • REQUEST_CACHE_MAX - The maximum number of AJAX requests that will be cached in memory.

When deploying this on your own, you'll need to have these values set through a .env file you ship yourself, or if you're using something like Netlify, you can define them in your dashboard.

Spin Up Locally

Run npm run serve to spin up a running version from localhost.

Build for Production

Run npm run build.

Deploy to Netlify

Netlify is amazing, so if you're in need of somewhere to host your own version of this project, I highly recommend it.

Deploy to Netlify

Caching

Out of the box, WP Vue will locally cache AJAX requests in memory, and then load them as needed. This first happens on page load, when all queried posts on the current and adjacent pages are cached for quick access later.

To keep things from getting out of control, a maximum request cache value is set. Once your cache reaches this max (regardless of how large each request is), the first request in memory will deleted as a new one is added. So, you shouldn't have to worry too much about an insane amount of data being locally stored as you move through posts.

Manually reloading the page will kill this cache. It will not persist.

Set Endpoint via URL Parameter

If you'd like to share link to a version of WP Vue that uses a different endpoint than what's set via the code, you can pass that endpoint in as a URL parameter:

Example: https://wp.netlify.com?endpoint=https://css-tricks.com/wp-json/wp/v2

Instead of using the default, this will use whatever endpoint you provide in the URL.

Contribute

Please do! See the <CONTRIBUTING.md> for details.

License

MIT © Alex MacArthur

You can’t perform that action at this time.