From 5adf97494df558a3ae0d38f73bbbd6022bf9a518 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 20 Jun 2024 20:53:04 +0200 Subject: [PATCH] feat: add Letters to the Editor post type Introduced a new custom post type "Letters to the Editor" with corresponding archive and single templates. Enhanced post type functionality includes support for featured images, authors, excerpts, and comments. Added pagination and a meta box for article authors to improve user interaction and content management. --- archive-letter.php | 44 ++++++++++++++++++++++++++++++++++ functions.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++ single-letter.php | 27 +++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 archive-letter.php create mode 100644 single-letter.php diff --git a/archive-letter.php b/archive-letter.php new file mode 100644 index 0000000..e4a9b8a --- /dev/null +++ b/archive-letter.php @@ -0,0 +1,44 @@ + + + +
+

Letters to the Editor

+
+ +
+
+ + <?php the_title(); ?> + +
+
+

|

+

+ Read More +
+
+
+ +

+ +
+
+
+ $wp_query->max_num_pages, + )); + ?> +
+
+
+ + \ No newline at end of file diff --git a/functions.php b/functions.php index e10c7a4..0939a85 100644 --- a/functions.php +++ b/functions.php @@ -409,3 +409,63 @@ function redirect_doi_to_article($query) } add_action('parse_query', 'redirect_doi_to_article'); + +function create_letter_post_type() { + $labels = array( + 'name' => _x('Letters to the Editor', 'Post type general name', 'duck-behavior-journal'), + 'singular_name' => _x('Letter to the Editor', 'Post type singular name', 'duck-behavior-journal'), + 'menu_name' => _x('Letters to the Editor', 'Admin Menu text', 'duck-behavior-journal'), + 'name_admin_bar' => _x('Letter to the Editor', 'Add New on Toolbar', 'duck-behavior-journal'), + 'add_new' => __('Add New', 'duck-behavior-journal'), + 'add_new_item' => __('Add New Letter', 'duck-behavior-journal'), + 'new_item' => __('New Letter', 'duck-behavior-journal'), + 'edit_item' => __('Edit Letter', 'duck-behavior-journal'), + 'view_item' => __('View Letter', 'duck-behavior-journal'), + 'all_items' => __('All Letters', 'duck-behavior-journal'), + 'search_items' => __('Search Letters', 'duck-behavior-journal'), + 'parent_item_colon' => __('Parent Letters:', 'duck-behavior-journal'), + 'not_found' => __('No letters found.', 'duck-behavior-journal'), + 'not_found_in_trash' => __('No letters found in Trash.', 'duck-behavior-journal'), + 'featured_image' => _x('Featured Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'duck-behavior-journal'), + 'set_featured_image' => _x('Set featured image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'duck-behavior-journal'), + 'remove_featured_image' => _x('Remove featured image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'duck-behavior-journal'), + 'use_featured_image' => _x('Use as featured image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'duck-behavior-journal'), + 'archives' => _x('Letter archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'duck-behavior-journal'), + 'insert_into_item' => _x('Insert into letter', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'duck-behavior-journal'), + 'uploaded_to_this_item' => _x('Uploaded to this letter', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'duck-behavior-journal'), + 'filter_items_list' => _x('Filter letters list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'duck-behavior-journal'), + 'items_list_navigation' => _x('Letters list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'duck-behavior-journal'), + 'items_list' => _x('Letters list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'duck-behavior-journal'), + ); + + $args = array( + 'labels' => $labels, + 'public' => true, + 'publicly_queryable' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'query_var' => true, + 'rewrite' => array('slug' => 'letter'), + 'capability_type' => 'post', + 'has_archive' => true, + 'hierarchical' => false, + 'menu_position' => null, + 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'), + ); + + register_post_type('letter', $args); +} +add_action('init', 'create_letter_post_type'); + +function add_article_meta_boxes() { + add_meta_box( + 'article_authors', + __('Authors', 'duck-behavior-journal'), + 'render_article_authors_meta_box', + array('letter'), + 'side', + 'default' + ); +} + +add_action('add_meta_boxes', 'add_letter_meta_boxes'); diff --git a/single-letter.php b/single-letter.php new file mode 100644 index 0000000..13c22c6 --- /dev/null +++ b/single-letter.php @@ -0,0 +1,27 @@ + + + +
+
+
+ +

+ | + + <?php the_title(); ?> + + + +
+
+
+ + \ No newline at end of file