Comments (3)
I think I am looking for something similar. I would like to connect this "sample" to my wordpress api and useless WP just as headless Backend and this "sample" as front. Any suggestion how to do it?
from samples.
Yes, I am looking for the same. Rest API call in AMP page.
from samples.
Do you mean requesting data from the WordPress REST API? If using the official AMP plugin for WordPress, the necessary CORS headers are added automatically. The headers are added automatically by AMP_HTTP::send_cors_headers()
whenever the request includes the __amp_source_origin
query param, which AMP adds automatically. So as long as WordPress is handling the fetch request, then the necessary CORS headers should all be supplied automatically.
So you just use the rest_url()
that WordPress provides. For example, here is a shortcode that shows the latest posts:
add_shortcode(
'amp_latest_posts',
function() {
$endpoint = rest_url( 'wp/v2/posts' );
/*
* Enqueue scripts for when shortcode is used on non-AMP pages. These are unnecessary on AMP pages because the
* post-processor will automatically add them when it encounters <amp-list>.
*/
wp_enqueue_script( 'amp-list' );
wp_enqueue_script( 'amp-mustache' );
ob_start();
?>
<amp-list src="<?php echo esc_url( $endpoint ); ?>" items="." layout="fixed-height" height="300" width="auto">
<template type="amp-mustache">
<div>
<a href="{{link}}">{{title.rendered}}</a>
</div>
</template>
</amp-list>
<?php
return ob_get_clean();
}
);
from samples.
Related Issues (20)
- Dependency deprecation warning: babel-preset-es2015 (npm)
- Dependency deprecation warning: babel-preset-es2015 (npm)
- Error in running Amp-pwa sample HOT 5
- Unable to install amp-paywall-demo
- Remove Google+ from AMP Samples
- amp-camp fails to start
- Creating a PWAMP application using wordpress as CMS HOT 6
- Consider some accessibility for the top of the page at https://amp-article.herokuapp.com/ HOT 1
- AMP Camp: related products don't work when you click on item from cart
- In amp-update-cache sample we are getting amp_ts=undefined error.
- I tried to find the declaration the ${ampjs} but I did not find it. ¿Where is it? HOT 1
- Rename the default branch of this repo from `master` to `main` HOT 7
- Sample for angular
- Demo is down
- Dependency Dashboard
- ampproject/samples
- Samples
- Working Groups for amp
- Ampproject/examples HOT 1
- Sex video HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from samples.