From 33f4d65bed30f193a383595ae54dbebe87ffb1e4 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 20 Jun 2024 14:44:20 +0200 Subject: [PATCH] feat: add DOI functionality to articles Introduced DOI meta box with a generator button in the article editor to assign and display DOIs for articles. Added functionality to save DOI values and correspondingly set up rewrite rules and redirections based on DOI queries. Display DOI on the article single view page for enhanced article identification and accessibility. --- functions.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++ single-article.php | 3 ++ 2 files changed, 79 insertions(+) diff --git a/functions.php b/functions.php index 515f941..b9cb8d5 100644 --- a/functions.php +++ b/functions.php @@ -257,6 +257,15 @@ function add_article_meta_boxes() 'side', 'default' ); + + add_meta_box( + 'article_doi', + __('Article DOI', 'duck-behavior-journal'), + 'render_article_doi_meta_box', + 'article', + 'side', + 'default' + ); } add_action('add_meta_boxes', 'add_article_meta_boxes'); @@ -299,6 +308,32 @@ function render_article_authors_meta_box($post) ID, 'article_doi', true); +?> +
+

+ + +

+
+ +query_vars['doi'])) { + $doi = $query->query_vars['doi']; + $args = array( + 'post_type' => 'article', + 'meta_query' => array( + array( + 'key' => 'article_doi', + 'value' => $doi, + 'compare' => '=' + ) + ) + ); + $articles = new WP_Query($args); + if ($articles->have_posts()) { + $articles->the_post(); + wp_redirect(get_permalink(), 301); + exit; + } + } +} + +add_action('parse_query', 'redirect_doi_to_article'); diff --git a/single-article.php b/single-article.php index 2e9d6d8..0c8e918 100644 --- a/single-article.php +++ b/single-article.php @@ -15,6 +15,9 @@ the_author(); } ?> +

+ DOI: +