From 1bbc4f141c200a46b2471d35ad80311154b75ce7 Mon Sep 17 00:00:00 2001 From: FredericoAndrade Date: Mon, 9 Dec 2024 12:50:58 +0100 Subject: [PATCH] restrict gallery to post_status=publish, create create_gallery_instance function in wt-gallery, refactor all galleries to clean up shortcode call, create display_empty parameter for gallery, integrated jobs in teams page including new careers template, remove post counts from language page side menu --- .../plugins/wt-gallery/includes/queries.php | 37 ++++++++- .../includes/templates/gallery-careers.php | 11 +++ wp-content/plugins/wt-gallery/readme.md | 48 ++++++++++++ wp-content/plugins/wt-gallery/readme.txt | 23 ------ wp-content/plugins/wt-gallery/wt-gallery.php | 71 ++++++++++++++--- .../acf-json/group_6749e117c8a3a.json | 22 +----- .../themes/blankslate-child/front-page.php | 61 +++++++++------ .../modules/content-block--grid.php | 1 - .../modules/meta--languages-single.php | 6 +- .../modules/single-languages__fellows.php | 33 ++++---- .../modules/single-languages__resources.php | 30 +++++--- .../modules/single-languages__videos.php | 31 +++++--- .../blankslate-child/single-fellows.php | 30 +++++--- .../blankslate-child/single-languages.php | 30 +++++--- .../themes/blankslate-child/single-videos.php | 30 +++++--- .../themes/blankslate-child/stylus/main.css | 77 +++++++++++++------ .../themes/blankslate-child/stylus/main.styl | 1 + .../stylus/require/team-member--grid.styl | 2 +- .../stylus/require/team-member--partner.styl | 20 ++--- .../stylus/require/team-member--wide.styl | 19 +---- .../blankslate-child/stylus/require/team.styl | 35 +++++++++ .../blankslate-child/template-about-staff.php | 37 +++++++++ .../template-archive-success.php | 31 +++++--- .../template-giving-campaign-24.php | 30 +++++--- .../template-revitalization-fellows.php | 30 +++++--- 25 files changed, 497 insertions(+), 249 deletions(-) create mode 100644 wp-content/plugins/wt-gallery/includes/templates/gallery-careers.php create mode 100644 wp-content/plugins/wt-gallery/readme.md delete mode 100644 wp-content/plugins/wt-gallery/readme.txt create mode 100644 wp-content/themes/blankslate-child/stylus/require/team.styl diff --git a/wp-content/plugins/wt-gallery/includes/queries.php b/wp-content/plugins/wt-gallery/includes/queries.php index 55bb43fb..1b04cf46 100644 --- a/wp-content/plugins/wt-gallery/includes/queries.php +++ b/wp-content/plugins/wt-gallery/includes/queries.php @@ -8,6 +8,7 @@ function get_custom_gallery_query($atts = array()) { $defaults = array( + 'post_status' => 'publish', 'post_type' => 'languages', // videos, languages, fellows 'posts_per_page' => 6, 'orderby' => 'date', @@ -15,6 +16,8 @@ function get_custom_gallery_query($atts = array()) { 'meta_key' => '', 'meta_value' => '', 'paged' => 1, + 'taxonomy' => '', + 'term' => '', ); $args = wp_parse_args($atts, $defaults); @@ -63,15 +66,47 @@ function get_custom_gallery_query($atts = array()) { $args['meta_query'] = $meta_query; unset($args['meta_key']); unset($args['meta_value']); + } else if (!empty($atts['taxonomy']) && !empty($atts['term'])) { + $args['tax_query'] = array( + array( + 'taxonomy' => $atts['taxonomy'], + 'field' => 'slug', + 'terms' => $atts['term'], + ), + ); + } - // // Exclude current post from the query + // Exclude current post from the query $current_post_type = get_post_type(); if ($current_post_type === $args['post_type']) { $args['post__not_in'] = array(get_the_ID()); } $query = new WP_Query($args); + if (!empty($args['tax_query'])) { + $tax_query = $args['tax_query'][0]; + $terms = explode(',', $tax_query['terms']); + $terms = array_map('trim', $terms); + + if (count($terms) > 1) { + $args['tax_query'] = array('relation' => 'OR'); + foreach ($terms as $term) { + if (!empty($term)) { + $args['tax_query'][] = array( + 'taxonomy' => $tax_query['taxonomy'], + 'field' => $tax_query['field'], + 'terms' => $term, + ); + } + } + } else { + $args['tax_query'][0]['terms'] = $terms[0]; + } + } + + $query = new WP_Query($args); + // log_data($query,"dom"); return $query; } diff --git a/wp-content/plugins/wt-gallery/includes/templates/gallery-careers.php b/wp-content/plugins/wt-gallery/includes/templates/gallery-careers.php new file mode 100644 index 00000000..ac8cc59c --- /dev/null +++ b/wp-content/plugins/wt-gallery/includes/templates/gallery-careers.php @@ -0,0 +1,11 @@ + diff --git a/wp-content/plugins/wt-gallery/readme.md b/wp-content/plugins/wt-gallery/readme.md new file mode 100644 index 00000000..47116149 --- /dev/null +++ b/wp-content/plugins/wt-gallery/readme.md @@ -0,0 +1,48 @@ +# Wikitongues gallery features + +## Simple implementation + +``` php + // Gallery + $params = [ + 'title' => 'Other videos of ' . $language_names, + 'post_type' => 'videos', + 'custom_class' => 'full', + 'columns' => 5, + 'posts_per_page' => 5, + 'orderby' => 'rand', + 'order' => 'asc', + 'pagination' => 'false', + 'meta_key' => 'language_iso_codes', + 'meta_value' => $language_iso_codes, + 'selected_posts' => '', + 'display_blank' => '', + 'taxonomy' => '', + 'term' => '' + ]; + echo create_gallery_instance($params); +``` + +Note: Boolean type fields must be strings instead + +## flexible post types: + +* `languages` +* `videos` +* `fellows` +* `careers` +* `resources` + +Any post type is accessible to the plugin. However custom templates will be required in order to render new types. Templates follow the name pattern gallery-[type].php + +# Design +* Custom classes +* Grid control via number of columns and count of posts to load per page +* Sorting with `orderby` and `order` +* `Pagination` + +# Filtering + +* Filter my post metadata with `meta_key` and `meta_value` +* Filter by `taxonomy` and `term` +* Return arbitrary posts with `selected_posts` \ No newline at end of file diff --git a/wp-content/plugins/wt-gallery/readme.txt b/wp-content/plugins/wt-gallery/readme.txt deleted file mode 100644 index ac9a3c77..00000000 --- a/wp-content/plugins/wt-gallery/readme.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Wikitongues gallery features - -## Simple implementation - -echo do_shortcode('[custom_gallery title="" custom_class="" post_type="" columns="" posts_per_page="" orderby="" order="" pagination="" meta_key="" meta_value="" selected_posts=""]'); - -## flexible post types: languages, videos, fellows - -## arbitrary number of posts - -## arbitrary filtering - -## arbitrary sorting - -## togglable pagination - -## admin-defined posts - -# Design - -## arbitrary number of columns - -## full width and partial width \ No newline at end of file diff --git a/wp-content/plugins/wt-gallery/wt-gallery.php b/wp-content/plugins/wt-gallery/wt-gallery.php index 81e6aeb5..2ee9354c 100644 --- a/wp-content/plugins/wt-gallery/wt-gallery.php +++ b/wp-content/plugins/wt-gallery/wt-gallery.php @@ -99,6 +99,43 @@ function get_custom_title($post_type) { } } +function create_gallery_instance($params) { + $defaults = [ + 'title' => '', + 'custom_class' => '', + 'post_type' => 'post', + 'columns' => 1, + 'posts_per_page' => 3, + 'orderby' => 'date', + 'order' => 'desc', + 'pagination' => 'false', + 'meta_key' => '', + 'meta_value' => '', + 'selected_posts' => '', + 'display_blank' => 'true', + 'taxonomy' => '', + 'term' => '' + ]; + + $args = wp_parse_args($params, $defaults); + + return do_shortcode('[custom_gallery title="'. + $args['title'].'" custom_class="'. + $args['custom_class'].'" post_type="'. + $args['post_type'].'" columns="'. + $args['columns'].'" posts_per_page="'. + $args['posts_per_page'].'" orderby="'. + $args['orderby'].'" order="'. + $args['order'].'" pagination="'. + $args['pagination'].'" meta_key="'. + $args['meta_key'].'" meta_value="'. + $args['meta_value'].'" selected_posts="'. + $args['selected_posts'].'" display_blank="'. + $args['display_blank'].'" taxonomy="'. + $args['taxonomy'].'" term="'. + $args['term'].'"]'); +} + function custom_gallery($atts) { static $gallery_counter = 0; $gallery_counter++; @@ -117,6 +154,9 @@ function custom_gallery($atts) { 'pagination' => 'true', // string true or false 'gallery_id' => 'gallery_' . $gallery_counter, 'selected_posts' => array(), + 'display_blank' => 'true', // define whether to use the default blank state or string true or false + 'taxonomy' => '', + 'term' => '', ), $atts, 'custom_gallery'); $paged = get_query_var('paged') ? get_query_var('paged') : 1; @@ -130,21 +170,26 @@ function custom_gallery($atts) { // Query setup $args = array( - 'post_type' => $atts['post_type'], - 'posts_per_page' => $atts['posts_per_page'], - 'orderby' => $atts['orderby'], - 'order' => $atts['order'], - 'meta_key' => $atts['meta_key'], - 'meta_value' => $atts['meta_value'], - 'paged' => $paged, - 'columns' => $atts['columns'], - 'pagination' => $atts['pagination'], + 'post_type' => $atts['post_type'], + 'posts_per_page' => $atts['posts_per_page'], + 'orderby' => $atts['orderby'], + 'order' => $atts['order'], + 'meta_key' => $atts['meta_key'], + 'meta_value' => $atts['meta_value'], + 'paged' => $paged, + 'columns' => $atts['columns'], + 'pagination' => $atts['pagination'], + 'display_blank' => $atts['display_blank'], + 'taxonomy' => $atts['taxonomy'], + 'term' => $atts['term'], ); + // Merge in any additional arguments (like selected posts) if (!empty($selected_posts)) { $args['post__in'] = $selected_posts; } + // log_data($args,"dom"); $data_attributes = esc_attr(json_encode($args)); @@ -163,10 +208,12 @@ function custom_gallery($atts) { } $output .= render_gallery_items($query, $atts, $atts['gallery_id'], $paged, $data_attributes); } else { - if ($atts['title']) { - $output .= '

'.$atts['title'].'

'; + if ($atts['display_blank']==='true') { + if ($atts['title']) { + $output .= '

'.$atts['title'].'

'; + } + $output .= '

There are no other '.$atts['post_type'].' to display—yet.

'; } - $output .= '

There are no other '.$atts['post_type'].' to display—yet.

'; } $output .= ''; diff --git a/wp-content/themes/blankslate-child/acf-json/group_6749e117c8a3a.json b/wp-content/themes/blankslate-child/acf-json/group_6749e117c8a3a.json index 8af48015..49b41d3b 100644 --- a/wp-content/themes/blankslate-child/acf-json/group_6749e117c8a3a.json +++ b/wp-content/themes/blankslate-child/acf-json/group_6749e117c8a3a.json @@ -382,26 +382,6 @@ "toolbar": "full", "media_upload": 1, "delay": 0 - }, - { - "key": "field_6752e4ae660ec", - "label": "test", - "name": "test", - "aria-label": "", - "type": "text", - "instructions": "", - "required": 0, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "default_value": "", - "maxlength": "", - "placeholder": "", - "prepend": "", - "append": "" } ], "location": [ @@ -422,5 +402,5 @@ "active": true, "description": "", "show_in_rest": 0, - "modified": 1733485746 + "modified": 1733745042 } diff --git a/wp-content/themes/blankslate-child/front-page.php b/wp-content/themes/blankslate-child/front-page.php index cb29d0d6..955984d3 100644 --- a/wp-content/themes/blankslate-child/front-page.php +++ b/wp-content/themes/blankslate-child/front-page.php @@ -37,36 +37,49 @@ if ($custom_posts) { $post_ids = implode(',', wp_list_pluck($custom_posts, 'ID')); } - $custom_title = get_sub_field('custom_gallery_title'); - $custom_post_type = 'videos'; - $custom_class = 'full home'; - $custom_columns = 4; - $custom_posts_per_page = 4; - $custom_orderby = 'rand'; - $custom_order = 'asc'; - $custom_pagination = 'false'; - $custom_meta_key = ''; - $custom_meta_value = ''; - $custom_selected_posts = esc_attr($post_ids); - echo do_shortcode('[custom_gallery title="'.$custom_title.'" custom_class="'.$custom_class.'" post_type="'.$custom_post_type.'" columns="'.$custom_columns.'" posts_per_page="'.$custom_posts_per_page.'" orderby="'.$custom_orderby.'" order="'.$custom_order.'" pagination="'.$custom_pagination.'" meta_key="'.$custom_meta_key.'" meta_value="'.$custom_meta_value.'" selected_posts="'.$custom_selected_posts.'"]'); + // Gallery + $params = [ + 'title' => get_sub_field('custom_gallery_title'), + 'post_type' => 'videos', + 'custom_class' => 'full home', + 'columns' => 4, + 'posts_per_page' => 4, + 'orderby' => 'rand', + 'order' => 'asc', + 'pagination' => 'false', + 'meta_key' => '', + 'meta_value' => '', + 'selected_posts' => esc_attr($post_ids), + 'display_blank' => '', + 'taxonomy' => '', + 'term' => '' + ]; + echo create_gallery_instance($params); + } elseif ( get_row_layout() == 'custom_gallery_posts' && $row_id === 'fellows') { $custom_posts = get_sub_field('custom_gallery_post'); if ($custom_posts) { $post_ids = implode(',', wp_list_pluck($custom_posts, 'ID')); } - $custom_title = get_sub_field('custom_gallery_title'); - $custom_post_type = 'fellows'; - $custom_class = 'full home'; - $custom_columns = 4; - $custom_posts_per_page = 4; - $custom_orderby = 'rand'; - $custom_order = 'asc'; - $custom_pagination = 'false'; - $custom_meta_key = ''; - $custom_meta_value = ''; - $custom_selected_posts = esc_attr($post_ids); - echo do_shortcode('[custom_gallery title="'.$custom_title.'" custom_class="'.$custom_class.'" post_type="'.$custom_post_type.'" columns="'.$custom_columns.'" posts_per_page="'.$custom_posts_per_page.'" orderby="'.$custom_orderby.'" order="'.$custom_order.'" pagination="'.$custom_pagination.'" meta_key="'.$custom_meta_key.'" meta_value="'.$custom_meta_value.'" selected_posts="'.$custom_selected_posts.'"]'); + // Gallery + $params = [ + 'title' => get_sub_field('custom_gallery_title'), + 'post_type' => 'fellows', + 'custom_class' => 'full home', + 'columns' => 4, + 'posts_per_page' => 4, + 'orderby' => 'rand', + 'order' => 'asc', + 'pagination' => 'false', + 'meta_key' => '', + 'meta_value' => '', + 'selected_posts' => esc_attr($post_ids), + 'display_blank' => '', + 'taxonomy' => '', + 'term' => '' + ]; + echo create_gallery_instance($params); } } } diff --git a/wp-content/themes/blankslate-child/modules/content-block--grid.php b/wp-content/themes/blankslate-child/modules/content-block--grid.php index f2290dbd..8c882e0e 100644 --- a/wp-content/themes/blankslate-child/modules/content-block--grid.php +++ b/wp-content/themes/blankslate-child/modules/content-block--grid.php @@ -22,7 +22,6 @@ class="wt_content-block--thirds__image" - \ No newline at end of file diff --git a/wp-content/themes/blankslate-child/modules/meta--languages-single.php b/wp-content/themes/blankslate-child/modules/meta--languages-single.php index c71fe14c..1f9da8e8 100644 --- a/wp-content/themes/blankslate-child/modules/meta--languages-single.php +++ b/wp-content/themes/blankslate-child/modules/meta--languages-single.php @@ -26,19 +26,19 @@