Created
May 23, 2018 21:58
-
-
Save clarklab/f92ad9a57fdcd857b0888d9f30b2e330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<meta name="description" content="List Posts From WordPress Using REST API With cURL In PHP"> | |
<title>WordPress REST API</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> | |
</head> | |
<body class="bg-light"> | |
<div class="container"> | |
<div class="py-5 text-center"> | |
<p class="lead">List Posts From WordPress Using REST API With cURL In PHP</p> | |
</div> | |
<div class="row"> | |
<div class="col-md-12 order-md-1"> | |
<div class="list-group"> | |
<?php | |
$url="https://stricklyclark.wpengine.com/wp-json/wp/v2/posts"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_URL,$url); | |
$result=curl_exec($ch); | |
$posts = json_decode($result, true); | |
foreach ($posts as $post) { ?> | |
<a href="<?php echo $post['link']; ?>" class="list-group-item list-group-item-action flex-column align-items-start"> | |
<div class="d-flex w-100 justify-content-between"> | |
<h5 class="mb-1"><?php echo $post['title']['rendered']; ?></h5> | |
<small><?php echo date('F j, Y', strtotime($post['date'])); ?></small> | |
</div> | |
<p class="mb-1"><?php echo $post['excerpt']['rendered']; ?></p> | |
</a> | |
<?php } ?> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment