瀏覽代碼

:recycle: loading current and upcoming events and exhibitions by default | altering some styles | adjusted excerpt length filter | changed some navigation settings to use sortby

tags/0.9.0
j 4 年之前
父節點
當前提交
822c1c257c

+ 9
- 1
plugins/cia-endpoints/cia-end-points.php 查看文件

@@ -70,6 +70,10 @@ add_action( 'rest_api_init', function () {
70 70
     $sort_controller->register_custom_route('events/by-upcoming');
71 71
     $sort_controller = new Make_Sort_By('exhibition', 'by_upcoming');
72 72
     $sort_controller->register_custom_route('exhibitions/by-upcoming');
73
+    $sort_controller = new Make_Sort_By('event', 'by_current_and_upcoming');
74
+    $sort_controller->register_custom_route('events/by-current-and-upcoming');
75
+    $sort_controller = new Make_Sort_By('exhibition', 'by_current_and_upcoming');
76
+    $sort_controller->register_custom_route('exhibitions/by-current-and-upcoming');
73 77
 });
74 78
 
75 79
 /**
@@ -97,4 +101,8 @@ add_filter('wp_rest_cache/allowed_endpoints', function () {
97 101
         $allowed_endpoints['craft/v2'][] = 'artists';
98 102
 
99 103
     return $allowed_endpoints;
100
-}, 10, 1);
104
+}, 10, 1);
105
+
106
+add_filter('excerpt_length', function ($length) {
107
+    return 20;
108
+});

+ 23
- 0
plugins/cia-endpoints/includes/class.make-sortby.php 查看文件

@@ -92,6 +92,29 @@ class Make_Sort_By extends WP_REST_Controller {
92 92
         return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
93 93
     }
94 94
     
95
+    public function by_current_and_upcoming( $request ) {
96
+        global $wpdb;
97
+        $time = strval(time());
98
+        $start = 'exhibit-start-date';
99
+        $end = 'exhibit-end-date';
100
+        if($this->post_type == 'event') {
101
+            $start = 'event-start-time';
102
+            $end = 'event-end-time';
103
+        }
104
+        $res = $wpdb->get_results($wpdb->prepare(
105
+            "SELECT DISTINCT wp_posts.* FROM wp_posts 
106
+            JOIN wp_postmeta AS starts
107
+            ON (starts.post_id = wp_posts.ID AND starts.meta_key = %s AND starts.meta_value <= %s OR starts.meta_value > %s)
108
+            JOIN wp_postmeta AS ends
109
+            ON (ends.post_id = wp_posts.ID AND ends.meta_key = %s AND ends.meta_value >= %s)
110
+            WHERE post_type = %s AND post_status = 'publish'
111
+            ORDER BY starts.meta_value DESC",
112
+            $start, $time, $time, $end, $time, $this->post_type
113
+        ));
114
+        wp_reset_postdata();
115
+        return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
116
+    }
117
+    
95 118
     public function by_upcoming( $request ) {
96 119
         global $wpdb;
97 120
         $time = strval(time());

+ 2
- 2
plugins/cia-endpoints/includes/formats.php 查看文件

@@ -43,12 +43,12 @@ function default_post_format( $item, $include_content ) {
43 43
     if($item->post_type === 'event') {
44 44
         $filtered[start] = get_post_meta( $item->ID, 'event-start-time', true );
45 45
         $filtered[end] = get_post_meta( $item->ID, 'event-end-time', true );
46
-        $filtered[now] = time();
46
+        $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
47 47
     }
48 48
     if($item->post_type === 'exhibition') {
49 49
         $filtered[start] = get_post_meta( $item->ID, 'exhibit-start-date', true );
50 50
         $filtered[end] = get_post_meta( $item->ID, 'exhibit-end-date', true );
51
-        $filtered[now] = time();
51
+        $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
52 52
     }
53 53
 
54 54
     // Post categories and tags (store just the slugs)

+ 3
- 2
vue-theme/src/components/card.vue 查看文件

@@ -25,7 +25,7 @@ export default {
25 25
 @import '../sss/variables.sss'
26 26
 @import '../sss/theme.sss'
27 27
 .card
28
-    padding: $ms-0
28
+    padding: $ms--1
29 29
     overflow: hidden
30 30
     text-overflow: clip
31 31
     &--info
@@ -33,7 +33,8 @@ export default {
33 33
         justify-content: center
34 34
     header
35 35
         a
36
-            /* text-decoration: none */
36
+            font-size: $ms--1
37
+            text-decoration: none
37 38
     img
38 39
         width: 100%
39 40
         height: auto

+ 3
- 1
vue-theme/src/components/navigation/navigation.vue 查看文件

@@ -10,7 +10,9 @@ nav.main.w-max
10 10
                     h1.t-serif.t-up craft in america
11 11
             li.f-grow
12 12
             li(v-for="item in menuItems")
13
-                router-link(:to="`/${item}`")
13
+                router-link(v-if="['events','exhibitions'].includes(item)" :to="`/${item}/by-current-and-upcoming`")
14
+                    h5.t-up {{ item }}
15
+                router-link(v-else :to="`/${item}`")
14 16
                     h5.t-up {{ item }}
15 17
 
16 18
     .mobile-menu

+ 2
- 0
vue-theme/src/components/sidebars/sidebar.vue 查看文件

@@ -127,6 +127,8 @@ export default {
127 127
 @import '../../sss/variables.sss'
128 128
 @import '../../sss/theme.sss'
129 129
 aside.sidebar
130
+    p, h3
131
+        margin: 0
130 132
     position: sticky
131 133
     /* top: 65px */
132 134
     top: $ms-7

+ 10
- 4
vue-theme/src/pages/index.vue 查看文件

@@ -35,17 +35,15 @@
35 35
 import { postTypeGetters, scrollTop } from './mixin-post-types'
36 36
 import card from '@/components/card.vue'
37 37
 
38
-import { convertTitleCase, postTypes } from '@/utils/helpers'
38
+import { convertTitleCase, postTypes, sortTypes } from '@/utils/helpers'
39 39
 
40 40
 export default {
41 41
     mixins: [postTypeGetters, scrollTop],
42 42
     components: { card },
43 43
     data() { 
44 44
         return {
45
-            // firstRow: ['episodes', 'exhibitions', 'events', 'shorts', 'posts'],
46 45
             firstRow: ['episodes', 'exhibitions', 'events', 'artists', 'posts'],
47 46
             secondRow: 'artists', // This is only ONE post
48
-            // thirdRow: ['guides', 'objects', 'techniques', 'talks', 'center']
49 47
             thirdRow: ['episodes', 'exhibitions', 'events', 'artists', 'posts']
50 48
         }
51 49
     },
@@ -53,7 +51,15 @@ export default {
53 51
         // console.log(wp)
54 52
         postTypes.forEach(type => {
55 53
             const capitalizedType = convertTitleCase(type)
56
-            this.$store.dispatch(`getAll${capitalizedType}`)
54
+
55
+            // We try and fetch EVERYTHING except
56
+            // for EVENTS and EXHIBITIONS we only grab
57
+            // the current or upcoming on load
58
+            if(!['events', 'exhibitions'].includes(type)) {
59
+                this.$store.dispatch(`getAll${capitalizedType}`)
60
+            } else {
61
+                this.$store.dispatch(`getAll${capitalizedType}`, sortTypes.currentAndUpcoming)
62
+            }
57 63
         })
58 64
         this.checkAndSetHero('welcome')
59 65
     },

+ 4
- 17
vue-theme/src/pages/list.vue 查看文件

@@ -3,15 +3,10 @@
3 3
     article.f-grow
4 4
 
5 5
         header.center.t-up
6
-            //- breadcrumb links here at top of page probably not needed for list page as its obvious - delete probably       
7
-            breadcrumb.f-row.start
8
-                router-link(:to="`/${type}`")
9
-                    h5.t-up {{ type }}
10
-
11 6
             .title.f-row
12 7
                 h3 {{ type }} list
13 8
                 span(v-if="sortBy")
14
-                    h3 &nbsp;sorted by {{ sortBy.replace('-', ' ') }}
9
+                    h3 sorted {{ sortBy.replace('-', ' ') }}
15 10
 
16 11
             h3(v-if="!loaded") loading...
17 12
             .content(v-else-if="allPagesLoaded && type && allPages[type]" v-html="allPages[type].content")
@@ -25,17 +20,7 @@
25 20
             p {{ `show sidebar: ${sidebar}` }}
26 21
         
27 22
     sidebar(v-if="sidebar" :type="`${type}`" layout="list")
28
-        //- .shadow.t-up
29
-        //-     h3 Upcoming {{ type }}
30
-        //-     div
31
-        //-         p upcoming title
32
-        //-         p date-from: date-to: 
33
-        //-         p location
34
-        //-         br
35
-        //-         p upcoming title
36
-        //-         p date-from: date-to: 
37
-        //-         p location
38
-
23
+    
39 24
 </template>
40 25
 
41 26
 <script>
@@ -128,6 +113,8 @@ export default {
128 113
             let type = convertTitleCase(this.type)
129 114
             let sort = this.sortBy ? this.sortBy : to.path.split('/').pop()
130 115
             this.checkAndSetHero(this.type)
116
+            console.log('---')
117
+            console.log(sort)
131 118
             if(!this[`all${type}Loaded`] || sort) this.getPosts()
132 119
         }
133 120
     },

+ 4
- 2
vue-theme/src/pages/single.vue 查看文件

@@ -9,8 +9,10 @@
9 9
         header
10 10
             //- breadcrumb links at top of page, needs link routing
11 11
             breadcrumb.f-row.start.t-up
12
-                router-link(:to="`/${type}`")
13
-                    h5 {{ type }}
12
+                router-link(v-if="['events','exhibitions'].includes(type)" :to="`/${type}/by-current-and-upcoming`")
13
+                    h5.t-up {{ type }}
14
+                router-link(v-else :to="`/${type}`")
15
+                    h5.t-up {{ type }}
14 16
                 //- h5 &#8226;
15 17
                 h5 &#62;
16 18
                 router-link(:to="`/${type}/${post.slug}`")

+ 20
- 0
vue-theme/src/router/routes.js 查看文件

@@ -30,6 +30,26 @@ export default [
30 30
         component: listPage,
31 31
         props: { sidebar: true, grid: true, sortBy: `${sortTypes.material}` },
32 32
     },
33
+    {
34
+        path: `/:type/${sortTypes.past}`,
35
+        component: listPage,
36
+        props: { sidebar: true, sortBy: `${sortTypes.past}` },
37
+    },
38
+    {
39
+        path: `/:type/${sortTypes.current}`,
40
+        component: listPage,
41
+        props: { sidebar: true, sortBy: `${sortTypes.current}` },
42
+    },
43
+    {
44
+        path: `/:type/${sortTypes.currentAndUpcoming}`,
45
+        component: listPage,
46
+        props: { sidebar: true, sortBy: `${sortTypes.currentAndUpcoming}` },
47
+    },
48
+    {
49
+        path: `/:type/${sortTypes.upcoming}`,
50
+        component: listPage,
51
+        props: { sidebar: true, sortBy: `${sortTypes.upcoming}` },
52
+    },
33 53
     {
34 54
         path: `/:type/${sortTypes.alpha}`,
35 55
         component: listPage,

+ 4
- 0
vue-theme/src/utils/helpers.js 查看文件

@@ -13,6 +13,10 @@ const sortTypes = {
13 13
     material: 'by-material',
14 14
     artist: 'by-artist',
15 15
     episode: 'by-episode',
16
+    upcoming: 'by-upcoming',
17
+    current: 'by-current',
18
+    currentAndUpcoming: 'by-current-and-upcoming',
19
+    past: 'by-past',
16 20
 }
17 21
 
18 22
 /**

Loading…
取消
儲存