feat: add publication status taxonomy to articles

Introduced a hierarchical 'publication status' taxonomy for the 'article' post type, providing a structured way to categorize publication states. Updated front-end views to display the publication status of articles both in listings and on the single article page.

This enhancement improves the classification and visibility of articles based on their publication status, aiding in better content organization and user navigation.
This commit is contained in:
Kumi 2024-06-20 11:28:29 +02:00
parent 625a2f0639
commit 93ceb845aa
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 56 additions and 2 deletions

View file

@ -213,9 +213,38 @@ function create_article_post_type()
register_post_type('article', $args);
}
add_action('init', 'create_article_post_type');
function create_publication_status_taxonomy()
{
$labels = array(
'name' => _x('Publication Statuses', 'taxonomy general name', 'duck-behavior-journal'),
'singular_name' => _x('Publication Status', 'taxonomy singular name', 'duck-behavior-journal'),
'search_items' => __('Search Publication Statuses', 'duck-behavior-journal'),
'all_items' => __('All Publication Statuses', 'duck-behavior-journal'),
'parent_item' => __('Parent Publication Status', 'duck-behavior-journal'),
'parent_item_colon' => __('Parent Publication Status:', 'duck-behavior-journal'),
'edit_item' => __('Edit Publication Status', 'duck-behavior-journal'),
'update_item' => __('Update Publication Status', 'duck-behavior-journal'),
'add_new_item' => __('Add New Publication Status', 'duck-behavior-journal'),
'new_item_name' => __('New Publication Status Name', 'duck-behavior-journal'),
'menu_name' => __('Publication Status', 'duck-behavior-journal'),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'publication-status'),
);
register_taxonomy('publication_status', array('article'), $args);
}
add_action('init', 'create_publication_status_taxonomy', 0);
function add_article_meta_boxes()
{
add_meta_box(

View file

@ -40,7 +40,18 @@
?>
</p>
<p class="card-text"><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>" class="btn btn-outline-primary">Read More</a>
<p class="card-text">
<?php
$terms = get_the_terms(get_the_ID(), 'publication_status');
if (!empty($terms) && !is_wp_error($terms)) {
$term_list = array();
foreach ($terms as $term) {
$term_list[] = $term->name;
}
echo implode(', ', $term_list);
}
?>
<a href="<?php the_permalink(); ?>" class="btn btn-outline-primary">Read More</a>
</div>
</div>
</div>

View file

@ -15,7 +15,21 @@
the_author();
}
?>
<p class="text-muted">
<?php
$terms = get_the_terms(get_the_ID(), 'publication_status');
if (!empty($terms) && !is_wp_error($terms)) {
$term_list = array();
foreach ($terms as $term) {
$term_list[] = $term->name;
}
echo implode(', ', $term_list);
}
?>
</p>
<?php if (has_post_thumbnail()) : ?>
<img src="<?php the_post_thumbnail_url(); ?>" class="img-fluid mb-4" alt="<?php the_title(); ?>">
<?php endif; ?>
<?php the_content(); ?>
<?php endwhile;
endif; ?>