| Server IP : 198.244.165.102 / Your IP : 216.73.216.218 [ Web Server : nginx/1.24.0 System : Linux modovh-ub-01 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : colleary ( 1011) PHP Version : 8.3.23 Disable Function : NONE Domains : 2 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/midwest/public_html/wp-content/themes/midwest-vue-shell/ |
Upload File : |
<?php
/*
Template Name: News Archive Template
*/
get_header();
?>
<?php get_template_part('template-parts/content', 'custom-advertisement'); ?>
<!-- <div data-fuse="Article_top_leaderboard" style="min-height: 90px;"></div> -->
<?php get_template_part('template-parts/content', 'google-ads-top'); ?>
<section class="mid-content-wrap">
<div class="mid-content-container">
<div class="left-sidebar">
<!-- <div data-fuse="Article_sidebar_lhs" style="min-height: 600px;"></div> -->
</div>
<div class="container">
<div class="row">
<div class="col-md-12 mid-pad-ziro">
<!-- News Slider Start -->
<div class="mid-home-slider-wrap mid-pad--right-ziro mid-inner-news">
<div class="mid-home-slider-inner">
<div class="row">
<?php
// Build the archive URL from the raw HTTP request — strips the query
// string so ?paged=2 on page 2 still resolves to the listing base URL.
// Using $_SERVER avoids all $post / get_permalink() corruption issues.
$archive_url = trailingslashit(
strtok( ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '?' )
);
// Use a custom param (?np=) — WordPress has no rewrite rule for
// 'paged' on singular pages, so ?paged=2 triggers a canonical
// redirect to /page/2/ which 404s. ?np= is unknown to WordPress
// so it passes through untouched.
$paged = max( 1, (int) ( $_GET['np'] ?? 1 ) );
$args = array(
'post_type' => 'news', // Adjust if you have a custom post type
'posts_per_page' => 12, // Number of posts to display
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged, // Pass the current page number
);
$news_query = new WP_Query($args);
if ($news_query->have_posts()) :
while ($news_query->have_posts()) : $news_query->the_post(); ?>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="card">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>"><img src="<?php the_post_thumbnail_url('full'); ?>" class="card-img-top" alt="<?php the_title(); ?>"></a>
<?php else : ?>
<a href="<?php the_permalink(); ?>"><img src="/wp-content/uploads/2025/01/logo_large.webp" class="card-img-top" alt="<?php the_title(); ?>"></a>
<?php endif; ?>
<div class="card-body">
<span><b><?php echo get_the_date('M j, Y'); ?></b></span>
<h4 class="card-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class="card-text"><?php echo wp_trim_words(get_the_excerpt(), 20, '...'); ?></p>
<a href="<?php the_permalink(); ?>" class="btn btn-primary mid-read-more-btn">read more <i class="fa-solid fa-plus"></i></a>
</div>
</div>
</div>
<?php endwhile;
else : ?>
<div class="col-md-12">
<p>No news articles found.</p>
</div>
<?php endif;
wp_reset_postdata(); ?>
</div>
<div class="row">
<nav aria-label="Page navigation example" class="mid-pagination">
<?php
// type='array' returns one item per page-number so we can wrap
// each in <li> — putting raw <a> directly in <ul> is invalid HTML
// and browsers silently move those anchors before the <ul>, placing
// them on top of article cards and hijacking clicks.
$links = paginate_links( array(
'base' => $archive_url . '%_%',
'format' => '?np=%#%',
'current' => $paged,
'total' => $news_query->max_num_pages,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'array',
) );
?>
<?php if ( $links ) : ?>
<ul class="pagination">
<?php foreach ( $links as $link ) :
$active = strpos( $link, 'current' ) !== false ? ' active' : '';
?>
<li class="page-item<?php echo $active; ?>"><?php echo $link; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</nav>
</div>
</div>
</div>
<!-- News Slider End -->
</div>
</div>
</div>
<div class="right-sidebar">
<!-- <div data-fuse="Article_sidebar_rhs" style="min-height: 600px;"></div> -->
</div>
</div>
</section>
<?php get_template_part('template-parts/content', 'google-ads-bottom'); ?>
<!-- <div data-fuse="Article_bottom_leaderboard" style="min-height: 250px;"></div> -->
<?php get_footer('inner'); ?>