Skip to content

Commit

Permalink
spins up fellow categories
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericoAndrade committed Oct 10, 2024
1 parent 2a80f24 commit 57c83f2
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<li class="gallery-item">
<?php
$thumbnail_url = get_custom_image('fellows');
$fellow_year = get_field('fellow_year');
$location = get_field('fellow_location');
$fellow_language_preferred_name = get_field('fellow_language_preferred_name');
$thumbnail = '';
<?php
$categories = get_the_terms(get_the_ID(), 'fellow-category');
$category_names = implode(', ', array_map('esc_html', wp_list_pluck($categories, 'name')));

if ($thumbnail_url) {
$thumbnail = '<div class="thumbnail" style="background-image:url('.esc_url($thumbnail_url).');" alt="' . get_the_title() . '"></div><span class="thumbnail-spacer">&nbsp;</span>';
} else {
$thumbnail = '<div class="no-thumbnail"><p>Thumbnail unavailable</p></div><span class="thumbnail-spacer">&nbsp;</span>';
}

$metadata = '<div class="fellow-metadata"><h3>'.$fellow_language_preferred_name.'</h3>';
$metadata .= '<span><p>'.$location.'</p><p>'.$fellow_year.'</p></span></div>';
$thumbnail_url = get_custom_image('fellows');
$fellow_year = get_field('fellow_year');
$location = get_field('fellow_location');
$fellow_language_preferred_name = get_field('fellow_language_preferred_name');
$thumbnail = '';

echo '<a href="'.esc_url(get_permalink()).'">';
echo $thumbnail;
echo '<div><h3>' . $title . '</h3></div>';
echo $metadata;
echo '</a>';
?>
</li>
if ($thumbnail_url) {
$thumbnail = '<div class="thumbnail" style="background-image:url('.esc_url($thumbnail_url).');" alt="' . get_the_title() . '"></div><span class="thumbnail-spacer">&nbsp;</span>';
} else {
$thumbnail = '<div class="no-thumbnail"><p>Thumbnail unavailable</p></div><span class="thumbnail-spacer">&nbsp;</span>';
}


echo '<li class="gallery-item">';
echo '<a href="'.esc_url(get_permalink()).'">';
echo $thumbnail;
echo '<div><h3>' . $title . '</h3></div>';
$metadata = '<div class="fellow-metadata"><h3>'.$fellow_language_preferred_name.'</h3>';
$metadata .= '<p>'.$category_names.'</p><span><p>'.$location.'</p><p>'.$fellow_year.'</p></span></div>';
echo $metadata;
echo '</a>';
echo '</li>';
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"key": "taxonomy_6708065ac1b54",
"title": "Fellow Categories",
"menu_order": 0,
"active": true,
"taxonomy": "fellow-category",
"object_type": [
"fellows"
],
"advanced_configuration": 0,
"import_source": "",
"import_date": "",
"labels": {
"name": "Fellow Categories",
"singular_name": "Fellow Category",
"menu_name": "Fellow Categories",
"all_items": "All Fellow Categories",
"edit_item": "Edit Fellow Category",
"view_item": "View Fellow Category",
"update_item": "Update Fellow Category",
"add_new_item": "Add New Fellow Category",
"new_item_name": "New Fellow Category Name",
"search_items": "Search Fellow Categories",
"popular_items": "Popular Fellow Categories",
"separate_items_with_commas": "Separate fellow categories with commas",
"add_or_remove_items": "Add or remove fellow categories",
"choose_from_most_used": "Choose from the most used fellow categories",
"most_used": "",
"not_found": "No fellow categories found",
"no_terms": "No fellow categories",
"name_field_description": "",
"slug_field_description": "",
"desc_field_description": "",
"items_list_navigation": "Fellow Categories list navigation",
"items_list": "Fellow Categories list",
"back_to_items": "← Go to fellow categories",
"item_link": "Fellow Category Link",
"item_link_description": "A link to a fellow category"
},
"description": "",
"capabilities": {
"manage_terms": "manage_categories",
"edit_terms": "manage_categories",
"delete_terms": "manage_categories",
"assign_terms": "edit_posts"
},
"public": 1,
"publicly_queryable": 1,
"hierarchical": 0,
"show_ui": 1,
"show_in_menu": 1,
"show_in_nav_menus": 1,
"show_in_rest": 1,
"rest_base": "",
"rest_namespace": "wp\/v2",
"rest_controller_class": "WP_REST_Terms_Controller",
"show_tagcloud": 1,
"show_in_quick_edit": 1,
"show_admin_column": 0,
"rewrite": {
"permalink_rewrite": "taxonomy_key",
"with_front": "1",
"rewrite_hierarchical": "0"
},
"query_var": "post_type_key",
"query_var_name": "",
"default_term": {
"default_term_enabled": "0"
},
"sort": 0,
"meta_box": "default",
"meta_box_cb": "",
"meta_box_sanitize_cb": "",
"modified": 1728579191
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,41 @@ function add_fellows_custom_columns($columns) {
unset($columns['date']);
$columns['fellow_year'] = __('Year', 'fellows');
$columns['fellow_language'] = __('Language', 'fellows');

$columns['fellow_category'] = __('Category', 'textdomain');
return $columns;
}
add_filter('manage_fellows_posts_columns', 'add_fellows_custom_columns');

function fill_fellows_custom_columns($column, $post_id) {
switch ($column) {
case 'fellow_year':
$fellow_year = get_field('fellow_year', $post_id);
echo esc_html($fellow_year);
break;
case 'fellow_year':
$fellow_year = get_field('fellow_year', $post_id);
echo esc_html($fellow_year);
break;

case 'fellow_language':
$fellow_language = get_field('fellow_language', $post_id);
if ($fellow_language instanceof WP_Post) {
// If the ACF field returns a post object, display the post title
echo esc_html($fellow_language->post_title);
} elseif (is_array($fellow_language)) {
// If it's an array of post objects (multiple posts selected)
$titles = wp_list_pluck($fellow_language, 'post_title'); // Get titles of all posts
echo esc_html(implode(', ', $titles)); // Display them as a comma-separated list
} else {
echo __('No related post found', 'fellows'); // Handle cases where the field is empty or invalid
}
break;

case 'fellow_language':
$fellow_language = get_field('fellow_language', $post_id);
if ($fellow_language instanceof WP_Post) {
// If the ACF field returns a post object, display the post title
echo esc_html($fellow_language->post_title);
} elseif (is_array($fellow_language)) {
// If it's an array of post objects (multiple posts selected)
$titles = wp_list_pluck($fellow_language, 'post_title'); // Get titles of all posts
echo esc_html(implode(', ', $titles)); // Display them as a comma-separated list
} else {
echo __('No related post found', 'fellows'); // Handle cases where the field is empty or invalid
}
break;
case 'fellow_category': // New case for the custom taxonomy
$terms = get_the_terms($post_id, 'fellow-category');
if (!empty($terms) && !is_wp_error($terms)) {
$term_names = wp_list_pluck($terms, 'name'); // Get the names of all terms
echo esc_html(implode(', ', $term_names)); // Display them as a comma-separated list
} else {
echo __('No Category', 'fellows');
}
break;
}
}
add_action('manage_fellows_posts_custom_column', 'fill_fellows_custom_columns', 10, 2);
Expand All @@ -90,13 +100,15 @@ function fellows_custom_column_orderby($query) {
}

$orderby = $query->get('orderby');

if ('fellow_year' == $orderby) {
$query->set('meta_key', 'fellow_year');
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'fellow_year');
$query->set('orderby', 'meta_value_num');
}

if ('fellow_language' == $orderby) {
$query->set('meta_key', 'fellow_language');
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'fellow_language');
$query->set('orderby', 'meta_value');
}
}
add_action('pre_get_posts', 'fellows_custom_column_orderby');
112 changes: 53 additions & 59 deletions wp-content/themes/blankslate-child/modules/meta--fellows-single.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
<?php
// Function to generate a single language link with an optional preferred name
function generate_language_link($language, $preferred_name = '') {
if ($language instanceof WP_Post) {
$language_url = home_url('/languages/' . $language->post_name);
return '<a class="language" href="' . esc_url($language_url) . '"><span class="identifier">' . esc_html($language->post_title) . '</span><p>' . esc_html($preferred_name) . '</p></a>';
}
}

// Function to generate links for multiple languages
function generate_language_links($fellow_language) {
$output = '';

if ($fellow_language instanceof WP_Post) {
// Handle single language, use the global preferred name if passed
$preferred_name = get_post_meta($fellow_language->ID, 'standard_name', true);
print_r($preferred_name);
$output .= generate_language_link($fellow_language, $preferred_name);
} elseif (is_array($fellow_language)) {
if (count($fellow_language) > 1) {
foreach ($fellow_language as $language) {
if ($language instanceof WP_Post) {
$preferred_name = get_post_meta($language->ID, 'standard_name', true);
$output .= generate_language_link($language, $preferred_name);
} else {
$output .= generate_language_link($language);
}
}
} else {
foreach ($fellow_language as $language) {
if ($language instanceof WP_Post) {
$preferred_name = get_field('fellow_language_preferred_name');
$output .= generate_language_link($language, $preferred_name);
} else {
$output .= generate_language_link($language);
}
}
}

} else {
$output .= '<span class="identifier">' . esc_html($fellow_language) . '</span>';
}

return $output;
}
?>

<section class="wt_fellow__meta">
<section class="head">
<div class="image" style="background-image:url('<?php echo esc_html($page_banner['banner_image']['url'])?>'"></div>
Expand All @@ -6,7 +53,6 @@
echo '<h1>' . esc_html($fellow_name) . '</h1>';?>
<?php if (array_filter(array_column($social_links, 'url'))): ?>
<article class="wt_fellow__meta--social">
<!-- <strong>Follow <?php echo esc_html(get_field('first_name')); ?></strong><br/> -->
<ul>
<?php foreach ($social_links as $platform => $data): ?>
<?php if ($data['url']): ?>
Expand All @@ -20,74 +66,22 @@
</ul>
</article>
<?php endif; ?>
<?php

?>
<section class="info">
<?php
echo '<p>' . esc_html($page_banner['banner_copy']) . '</p>';
if ($fellow_year) {
echo '<a class="cohort" href="'.$revitalization_fellows_url.'">' . esc_html($fellow_year) . ' cohort</a>';
}
// Function to generate a single language link with an optional preferred name
function generate_language_link($language, $preferred_name = '') {
if ($language instanceof WP_Post) {
$language_url = home_url('/languages/' . $language->post_name);
return '<a class="language" href="' . esc_url($language_url) . '"><span class="identifier">' . esc_html($language->post_title) . '</span><p>' . esc_html($preferred_name) . '</p></a>';
}
}

// Function to generate links for multiple languages
function generate_language_links($fellow_language) {
$output = '';

if ($fellow_language instanceof WP_Post) {
// Handle single language, use the global preferred name if passed
$preferred_name = get_post_meta($fellow_language->ID, 'standard_name', true);
print_r($preferred_name);
$output .= generate_language_link($fellow_language, $preferred_name);
} elseif (is_array($fellow_language)) {
if (count($fellow_language) > 1) {
foreach ($fellow_language as $language) {
if ($language instanceof WP_Post) {
$preferred_name = get_post_meta($language->ID, 'standard_name', true);
$output .= generate_language_link($language, $preferred_name);
} else {
$output .= generate_language_link($language);
}
}
} else {
foreach ($fellow_language as $language) {
if ($language instanceof WP_Post) {
$preferred_name = get_field('fellow_language_preferred_name');
$output .= generate_language_link($language, $preferred_name);
} else {
$output .= generate_language_link($language);
}
}
}
echo '<p class="categories">'.$category_names.'</p>';
if ($fellow_year) {
echo '<a class="cohort" href="'.$revitalization_fellows_url.'">' . esc_html($fellow_year) . ' cohort</a>';
}

} else {
$output .= '<span class="identifier">' . esc_html($fellow_language) . '</span>';
}
$lang_output = generate_language_links($fellow_language);

return $output;
}

// Main rendering block
$lang_output = generate_language_links($fellow_language);

echo $lang_output;
echo '<span class="languages">'.$lang_output.'</span>';
?>
</section>
</div>
</section>

<!-- <article>
<strong><?php echo $fellow_name; ?> is a member of the Wikitongues Language Revitalization Fellowship's <?php echo $fellow_year; ?> cohort.</strong>
</article> -->

<!-- links other than the fellow's personal social media or website -->
<?php if ( have_rows('custom_links') ): ?>
<article class="wt_fellow__meta--links">
<strong>Links</strong><br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
$links = [
'ethnologue' => $ethnologue,
'glottolog' => $glottolog,
'OLAC' => $olac,
'wikipedia' => $wikipedia,
'Open Language Archives Community' => $olac,
'English Wikipedia Article' => $wikipedia,
];
?>
<div class="wt_meta--languages-single">
Expand Down
2 changes: 2 additions & 0 deletions wp-content/themes/blankslate-child/single-fellows.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
$fellow_language = get_field('fellow_language');
$fellow_location = get_field('fellow_location');
$fellow_language_preferred_name = get_field('fellow_language_preferred_name');
$categories = get_the_terms(get_the_ID(), 'fellow-category');
$category_names = implode(', ', array_map('esc_html', wp_list_pluck($categories, 'name')));
$social_links = [
'email' => ['url' => get_field('email'), 'icon' => 'fa-brands fa-square-email'],
'facebook' => ['url' => get_field('facebook'), 'icon' => 'fa-brands fa-square-facebook'],
Expand Down
Loading

0 comments on commit 57c83f2

Please sign in to comment.