wp-duckbehaviorjournal/archive-article.php
Kumi 9ece16c681
feat: improve pagination styling and functionality
Updated pagination implementation in `archive-article.php` and `archive-letter.php` to use global `$wp_query` for accurate page counts and improved navigation. Enhanced user experience by adding more pagination options such as `prev_next`, `show_all`, and customizable text for previous and next links.

Added new styles to `style.css` to center pagination, improve link aesthetics, and highlight the current page.

This enhancement provides a more user-friendly interface and consistent appearance across archive pages.
2024-08-03 12:59:01 +02:00

108 lines
No EOL
5.2 KiB
PHP

<?php get_header(); ?>
<!-- Archive Content -->
<section class="container my-5">
<h1 class="display-4 text-center">Articles</h1>
<div class="row mb-4">
<div class="col-md-6">
<form method="GET" action="" class="form-inline justify-content-start">
<div class="form-group mb-2">
<label for="publication_status" class="sr-only"><?php _e('Publication Status', 'duck-behavior-journal'); ?></label>
<select name="publication_status" id="publication_status" class="form-control" onchange="this.form.submit()">
<option value=""><?php _e('All Statuses', 'duck-behavior-journal'); ?></option>
<?php
$terms = get_terms(array(
'taxonomy' => 'publication_status',
'hide_empty' => false,
));
foreach ($terms as $term) {
$selected = (isset($_GET['publication_status']) && $_GET['publication_status'] == $term->slug) ? 'selected' : '';
echo '<option value="' . esc_attr($term->slug) . '" ' . $selected . '>' . esc_html($term->name) . '</option>';
}
?>
</select>
</div>
<button type="submit" class="btn btn-primary mb-2 ml-2"><?php _e('Filter', 'duck-behavior-journal'); ?></button>
</form>
</div>
<div class="col-md-6">
<form method="GET" action="" class="form-inline justify-content-end">
<div class="form-group mb-2">
<label for="s" class="sr-only"><?php _e('Search', 'duck-behavior-journal'); ?></label>
<input type="text" name="s" id="s" class="form-control" placeholder="<?php _e('Search', 'duck-behavior-journal'); ?>" value="<?php echo get_search_query(); ?>">
</div>
<button type="submit" class="btn btn-primary mb-2 ml-2"><?php _e('Search', 'duck-behavior-journal'); ?></button>
</form>
</div>
</div>
<div class="row">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>">
<img src="<?php the_post_thumbnail_url(); ?>" class="card-img-top" alt="<?php the_title(); ?>">
</a>
<?php endif; ?>
<div class="card-body">
<a href="<?php the_permalink(); ?>">
<h5 class="card-title"><?php the_title(); ?></h5>
</a>
<p class="card-text">
<?php
$authors = get_post_meta(get_the_ID(), 'article_authors', true);
if (!empty($authors)) {
echo esc_html($authors[0]);
if (count($authors) > 1) {
echo ' et al.';
}
} else {
the_author();
}
?>
</p>
<p class="card-text"><?php the_excerpt(); ?></p>
<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);
}
?>
</p>
<a href="<?php the_permalink(); ?>" class="btn btn-outline-primary">Read More</a>
</div>
</div>
</div>
<?php endwhile;
else : ?>
<p><?php _e('Sorry, no articles found.', 'duck-behavior-journal'); ?></p>
<?php endif; ?>
</div>
<div class="row">
<div class="pagination col-md-12">
<?php
global $wp_query;
echo paginate_links(array(
'total' => $wp_query->max_num_pages,
'current' => max(1, get_query_var('paged')),
'format' => '?paged=%#%',
'show_all' => false,
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => __('« Prev', 'duck-behavior-journal'),
'next_text' => __('Next »', 'duck-behavior-journal'),
'type' => 'plain'
));
?>
</div>
</div>
</section>
<?php get_footer(); ?>