From c738ed6f8975f163e129ee7fbf4e69771da66890 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 3 Aug 2024 17:12:13 +0200 Subject: [PATCH] refactor: extract publication status formatting Moved code for fetching and displaying publication status terms into a reusable function `display_publication_status_terms`. This simplifies template files by reducing redundancy and enhances maintainability. The new function also supports displaying terms with associated colors. --- archive-article.php | 11 +---------- functions.php | 11 +++++++++++ index.php | 11 +---------- single-article.php | 12 ++---------- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/archive-article.php b/archive-article.php index b6cea57..2aa26fa 100644 --- a/archive-article.php +++ b/archive-article.php @@ -63,16 +63,7 @@

- name; - } - echo implode(', ', $term_list); - } - ?> +

Read More diff --git a/functions.php b/functions.php index 25785b1..6bb2774 100644 --- a/functions.php +++ b/functions.php @@ -326,6 +326,17 @@ function enqueue_color_picker($hook_suffix) add_action('admin_enqueue_scripts', 'enqueue_color_picker'); +function display_publication_status_terms($post_id) { + $terms = get_the_terms($post_id, 'publication_status'); + if (!empty($terms) && !is_wp_error($terms)) { + foreach ($terms as $term) { + $color = get_term_meta($term->term_id, 'publication_status_color', true); + $color_style = $color ? ' style="color:' . esc_attr($color) . ';"' : ''; + echo '' . esc_html($term->name) . ' '; + } + } +} + function add_article_meta_boxes() { add_meta_box( diff --git a/index.php b/index.php index 807ee3b..1547640 100644 --- a/index.php +++ b/index.php @@ -45,16 +45,7 @@

- name; - } - echo implode(', ', $term_list); - } - ?> +

Read More diff --git a/single-article.php b/single-article.php index fc1a37e..c58e6eb 100644 --- a/single-article.php +++ b/single-article.php @@ -23,16 +23,8 @@

- Status: name; - } - echo implode(', ', $term_list); - } - ?> + Status: +

Abstract: