Advertisement
frowdst

wp-json

Feb 23rd, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. if ($url="https://test.wordpress.com/wp-json/wp/v2/posts/".$_GET ['id']) {
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6. curl_setopt($ch, CURLOPT_URL,$url);
  7. $result=curl_exec($ch);
  8. $posts = json_decode($result, true);
  9. echo "
  10. <div class='d-flex w-100 justify-content-between'>
  11. <h2 class='mb-1'>".$posts['title']['rendered']."</h2>
  12. <small>".date('F j, Y', strtotime($posts['date']))."</small>
  13. </div>
  14. <p class='mb-1'>".$posts['content']['rendered']."</p>
  15. ";
  16. }
  17. else {
  18. $url="https://test.wordpress.com/wp-json/wp/v2/posts?per_page=3";
  19. foreach ($posts as $post) {
  20. echo "
  21. <div class='col-md-4 wow fadeInUp'>
  22. <div class='about-col'>
  23. <h2 class='title'>
  24. <a href='".base_url('pages')."?id=".$post['id']."'>
  25. <h5 class='mb-1'>".$post['title']['rendered']."</h5>
  26. <small>".date('F j, Y', strtotime($post['date']))."</small>
  27. </a>
  28. </h2>
  29. ".$post['content']['rendered']."
  30. </div>
  31. </div>";
  32. }
  33. }
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement