Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57 from washingtonstateuniversity/fix-pagination
Browse files Browse the repository at this point in the history
Fix page pagination
  • Loading branch information
Adam Turner authored Aug 2, 2018
2 parents cb1b5e6 + b4aab13 commit 0368eab
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 135 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ This document details all notable changes to the WSU HRS Child Theme. Uses [Sema
### Removed (for deprecated features removed in this release)
-->

## 0.18.1 (2018-08-02)

### Fixed

- Fix #55 and close #56, use main WP Query wherever possible instead of custom queries to maintain pagination.

### Changed

- No longer override the posts_per_page setting on the posts home page.
- Switch from using a custom WP_Query in `home.php` to using only the main query and filtering it with `pre_get_posts` and formatting with a counter.
- Switched from using a custom WP_Query on HRS taxonomy archive pages to just filtering the full main query.

### Removed

- Stop filtering the main query on the HRS taxonomy archive pages.
- Removed unneeded page query var from `archive.php`.

## 0.17.8 (2018-07-31)

### Fixed
Expand Down
2 changes: 0 additions & 2 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
$archive_title = __( 'HRS News' );
}

$page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

$is_feature = false;

get_header();
Expand Down
2 changes: 1 addition & 1 deletion assets/css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @since 0.17.3
*/
function hrs_get_theme_version() {
$hrs_version = '0.17.8';
$hrs_version = '0.18.1';

return $hrs_version;
}
Expand Down
109 changes: 38 additions & 71 deletions home.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
*/
global $is_feature;

$page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$is_feature = false;
$exclude_post_id = array();

get_header();
?>

Expand All @@ -22,87 +18,58 @@
<h1><?php esc_html_e( 'News from Human Resource Services', 'hrs-wsu-edu' ) ?></h1>
</header>

<?php
// Display the feature layout and reminders section only on the first page.
if ( have_posts() && ! is_paged() ) :
?>

<section class="row single gutter pad-ends features">
<div class="column one">
<div class="articles-list">
<?php if ( have_posts() ) :
$result_count = 0;
while ( have_posts() ) : the_post();
if ( ! is_paged() ) {

if ( 0 === $result_count ) {
$is_feature = true;
?>
<section class="row single gutter pad-ends features">
<div class="column one">
<div class="articles-list">
<?php
while ( have_posts() ) : the_post();

$exclude_post_id[] = get_the_ID();

$is_feature = true;

get_template_part( 'articles/archive-content' );
}

break;
if ( 1 === $result_count ) {
$is_feature = false;

endwhile;
?>
</div><!-- .articles-list -->

</div>

<?php
$reminders = WSU\HRS\Queries\get_reminder_posts( 'objects' );

if ( $reminders->have_posts() ) :
?>
<div class="reminders">
<h2><?php esc_html_e( 'Reminders', 'hrs-wsu-edu' ); ?></h2>
<ul>
<?php
while ( $reminders->have_posts() ) : $reminders->the_post();
$exclude_post_id[] = get_the_ID();
$reminders = WSU\HRS\Queries\get_reminder_posts( 'objects' );

if ( $reminders->have_posts() ) {
?>
<li><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<div class="reminders">
<h2><?php esc_html_e( 'Reminders', 'hrs-wsu-edu' ); ?></h2>
<ul>
<?php while ( $reminders->have_posts() ) : $reminders->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</div>
<?php
endwhile;
?>
</ul>
</div>
<?php
endif;
?>

</div>
</section>

<?php
endif; // End of the feature and reminders sections.
}

$is_feature = false;

$archive_query = new WP_Query( array(
'posts_per_page' => 10,
'post__not_in' => $exclude_post_id,
'paged' => absint( $page ),
) );

if ( $archive_query->have_posts() ) :
$output_post_count = 0;

while ( $archive_query->have_posts() ) : $archive_query->the_post();
wp_reset_postdata();
?>
</div>
</section><!-- .features -->

// Display special layout and content on the first page only.
if ( ! is_paged() ) {
if ( 0 === $output_post_count ) {
?>
<section class="row single gutter pad-ends latest">
<div class="column one">
<div class="cards">
<?php
}

if ( 4 === $output_post_count ) {
if ( 5 === $result_count ) {
?>
</div>
</div>
</section>
</section><!-- .latest -->

<section class="row single gutter pad-ends hrs-units-browse">
<div class="column one">
Expand All @@ -118,13 +85,13 @@
<section class="row single gutter pad-ends article-archive">
<div class="column one">
<header>
<h2>More News from HRS</h2>
<h2><?php esc_html_e( 'More News from HRS', 'hrs-wsu-edu' ); ?></h2>
</header>
<div class="articles-list">
<?php
}
} else {
if ( 0 === $output_post_count ) {
if ( 0 === $result_count ) {
?>
<section class="row single gutter pad-ends article-archive">
<div class="column one">
Expand All @@ -135,14 +102,14 @@

get_template_part( 'articles/archive-content' );

$output_post_count++;
$result_count++;

endwhile;
?>
</div>
</div><!--/column-->
</section>

</div>
</div><!--/column-->
</section>
<?php
endif;

Expand Down
17 changes: 7 additions & 10 deletions includes/hrs-queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,24 @@
add_action( 'pre_get_posts', 'WSU\HRS\Queries\hrs_filter_query', 10 );

/**
* Filters the main tax query for the HRS Units tax.
* Filters the main WP_Query.
*
* Adjust the main taxonomy query for the HRS Units taxonomy to display only the
* first result. For use in the featured article layout template.
* Adjust the main query on the posts home page to filter out posts in the
* "Reminder" category to prevent duplicate results.
*
* @param \WP_Query $query
*/
function hrs_filter_query( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}

/* Exclude posts in the reminder category from the posts home query. */
// Exclude posts in the reminder category from the posts home query.
if ( ! is_admin() && is_home() && $query->is_main_query() ) {
$reminders = get_category_by_slug( 'reminders' );
$query->set( 'category__not_in', intval( $reminders->term_id ) );
return;
}

if ( is_admin() || ! $query->is_main_query() || ! is_tax( 'hrs_unit' ) ) {
return;
}

$query->set( 'posts_per_page', 1 );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hrs.wsu.edu",
"version": "0.17.8",
"version": "0.18.1",
"repository": {
"type": "git",
"url": "https://github.com/washingtonstateuniversity/hrs.wsu.edu"
Expand Down
2 changes: 1 addition & 1 deletion src/assets/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Adam Turner, WSU University Communications
Author URI: https://web.wsu.edu/
Description: A child theme of the WSU Web Communications Spine template.
Template: wsuspine
Version: 0.17.8
Version: 0.18.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Adam Turner, WSU University Communications
Author URI: https://web.wsu.edu/
Description: A child theme of the WSU Web Communications Spine template.
Template: wsuspine
Version: 0.17.8
Version: 0.18.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
71 changes: 24 additions & 47 deletions taxonomy-hrs_unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
*/
global $is_feature;

$page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$exclude_post_id = array();
$is_feature = false;

get_header();
?>

Expand All @@ -23,59 +19,40 @@
<h1><?php printf( esc_html__( 'HRS News from %s', 'hrs-wsu-edu' ), single_term_title( '', false ) ); ?></h1>
</header>

<?php
if ( have_posts() && 1 === $page ) :
?>

<section class="row single gutter pad-ends features">
<div class="column one">
<div class="articles-list">
<?php if ( have_posts() ) :

<?php
while ( have_posts() ) : the_post();
$result_count = 0;

$exclude_post_id[] = get_the_ID();
while ( have_posts() ) : the_post();

$is_feature = true;

get_template_part( 'articles/archive-content' );
if ( ! is_paged() ) {

endwhile;
if ( 0 === $result_count ) {
$is_feature = true;
?>
<section class="row single gutter pad-ends features">
<div class="column one">
<div class="articles-list">
<?php
}

</div>
</div>
</section>

<?php
endif;

$is_feature = false;

$archive_query = \WSU\HRS\Queries\get_hrs_unit_posts( array(
'post__not_in' => $exclude_post_id,
'paged' => $page,
) );

if ( $archive_query->have_posts() ) :
$output_post_count = 0;

while ( $archive_query->have_posts() ) : $archive_query->the_post();

if ( ! is_paged() ) {
if ( 0 === $output_post_count ) {
if ( 1 === $result_count ) {
$is_feature = false;
?>
</div>
</div>
</section><!-- .features -->
<section class="row single gutter pad-ends latest">
<div class="column one">
<div class="cards">
<?php
}

if ( 3 === $output_post_count ) {
if ( 4 === $result_count ) {
?>
</div>
</div>
</section>
</section><!-- .latest -->
<section class="row single gutter pad-ends article-archive">
<div class="column one">
<header>
Expand All @@ -85,7 +62,7 @@
<?php
}
} else {
if ( 0 === $output_post_count ) {
if ( 0 === $result_count ) {
?>
<section class="row single gutter pad-ends article-archive">
<div class="column one">
Expand All @@ -96,18 +73,18 @@

get_template_part( 'articles/archive-content' );

$output_post_count++;
$result_count++;

endwhile;
?>
</div>
</div><!--/column-->
</section>

</div>
</div><!--/column-->
</section>
<?php
endif;

\WSU\HRS\Template_Tags\hrs_pagination( $archive_query->max_num_pages );
\WSU\HRS\Template_Tags\hrs_pagination();

get_template_part( 'parts/footers' );
?>
Expand Down

0 comments on commit 0368eab

Please sign in to comment.