Skip to content

Commit

Permalink
Merge pull request #272 from wikitongues/main
Browse files Browse the repository at this point in the history
staging deploy
  • Loading branch information
FredericoAndrade authored Dec 9, 2024
2 parents 0854c83 + aeef503 commit e7a6362
Show file tree
Hide file tree
Showing 25 changed files with 497 additions and 249 deletions.
37 changes: 36 additions & 1 deletion wp-content/plugins/wt-gallery/includes/queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

function get_custom_gallery_query($atts = array()) {
$defaults = array(
'post_status' => 'publish',
'post_type' => 'languages', // videos, languages, fellows
'posts_per_page' => 6,
'orderby' => 'date',
'order' => 'DESC',
'meta_key' => '',
'meta_value' => '',
'paged' => 1,
'taxonomy' => '',
'term' => '',
);

$args = wp_parse_args($atts, $defaults);
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<li class="gallery-item">
<?php
$title = get_the_title();
$location = get_field('location');

echo '<a href="">';
echo '<h3>' . $title . '</h3>';
echo '<p>&nbsp;— '.$location.'</p>';
echo '</a>';
?>
</li>
48 changes: 48 additions & 0 deletions wp-content/plugins/wt-gallery/readme.md
Original file line number Diff line number Diff line change
@@ -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`
23 changes: 0 additions & 23 deletions wp-content/plugins/wt-gallery/readme.txt

This file was deleted.

71 changes: 59 additions & 12 deletions wp-content/plugins/wt-gallery/wt-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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;
Expand All @@ -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));

Expand All @@ -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 .= '<h2 class="wt_sectionHeader">'.$atts['title'].'</h2>';
if ($atts['display_blank']==='true') {
if ($atts['title']) {
$output .= '<h2 class="wt_sectionHeader">'.$atts['title'].'</h2>';
}
$output .= '<p>There are no other '.$atts['post_type'].' to display—yet.</p>';
}
$output .= '<p>There are no other '.$atts['post_type'].' to display—yet.</p>';
}
$output .= '</div>';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -422,5 +402,5 @@
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1733485746
"modified": 1733745042
}
61 changes: 37 additions & 24 deletions wp-content/themes/blankslate-child/front-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class="wt_content-block--thirds__image"
<?php endif; ?>
<a href="<?php echo $content_block_cta_link; ?>" class="<?php echo $content_block_class; ?>">
<?php echo $content_block_cta_text; ?>
<i class="fa-regular fa-arrow-right-long"></i>
</a>
</aside>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
<ul class="resources">
<li>
<a href="#wt_single-languages__videos">
<h3>Videos <?php echo ($videos_count > 0 ? '(' . $videos_count . ')' : ''); ?></h3>
<h3>Videos</h3>
</a>
<a href="<?php echo home_url('/submit-a-video', 'relative'); ?>">Submit a video</a>
</li>
<li>
<a href="#wt_single-languages__lexicons">
<h3>Dictionaries, phrase books, and lexicons <?php echo ($lexicons_count > 0 ? '(' . $lexicons_count . ')' : ''); ?></h3>
<h3>Dictionaries, phrase books, and lexicons</h3>
</a>
<a href="<?php echo home_url('/submit-a-lexicon', 'relative'); ?>">Submit a lexicon</a>
</li>
<li>
<a href="#wt_single-languages__resources">
<h3>External Resources <?php echo ($external_resources_count > 0 ? '(' . $external_resources_count . ')' : ''); ?></h3>
<h3>External Resources</h3>
</a>
<a href="<?php echo home_url('/submit-a-resource', 'relative'); ?>">Recommend a resource</a>
</li>
Expand Down
Loading

0 comments on commit e7a6362

Please sign in to comment.