This repository was archived by the owner on Jul 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.php
More file actions
88 lines (60 loc) · 2.15 KB
/
Copy pathstack.php
File metadata and controls
88 lines (60 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace andyp\pulsestack\REST;
use \WP_REST_Request;
class stack {
public $posts;
public $result;
public $endpoint = "https://parkourpulse.com/wp-json/wp/v2/pulse";
public function __construct()
{
$this->REST_call();
$this->render();
}
/**
* https://rudrastyh.com/wordpress/rest-api-get-posts.html
*/
private function REST_call()
{
$transient = \get_transient( 'pulsestack' );
if( ! empty( $transient ) ) {
$this->posts = json_decode($transient);
return;
}
$response = \wp_remote_get( add_query_arg( array(
'per_page' => 5,
'pulse_category' => 4
), $this->endpoint ) );
if (is_wp_error($response)) {
return;
}
$this->posts = json_decode( $response['body'] ); // our posts are here
\set_transient( 'pulsestack', json_encode( $this->posts ), DAY_IN_SECONDS );
}
public function render()
{
if (!isset($this->posts)){
return;
}
shuffle($this->posts);
$output = '<ul class="parkourpulse flex overflow-hidden h-96" style="width:400%">';
foreach($this->posts as $key => $post )
{
// 1 = 'one', 12 = 'twelve'
$f = new \NumberFormatter("en", \NumberFormatter::SPELLOUT);
$id = $f->format($key);
$zebra = ($key++%2==1) ? 'odd' : 'even';
$output .= '<li class="'.$id.' '.$zebra.' w-1/5 h-1/2 lg:w-1/5 lg:h-2/3 p-8" style="transform: scaleX(1) scaleY(1);">';
$output .= '<div class="w-full h-full shadow lg:shadow-2xl rounded mb-2">';
$output .= '<img class="lazyload object-cover w-full h-full" src="'.$post->imageURL.'" alt="'.$post->title->rendered.'" width="'.$post->imageWidth.'" height="'.$post->imageHeight.'">';
$output .= '</div>';
$output .= '<div class="">'.$post->channelTitle.'</div>';
$output .= '</li>';
}
$output .= '</ul>';
$this->result = $output;
}
public function out()
{
return $this->result;
}
}