Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Post template] Update how sticky posts are displayed #35791

Closed
wants to merge 2 commits into from

Conversation

carolinan
Copy link
Contributor

@carolinan carolinan commented Oct 20, 2021

Description

Problem 1

If a WordPress install has no sticky posts, standard posts are displayed on the front when the query loop setting "Sticky posts" is set to "only".

The PR adds an early return depending on the setting and if there are sticky posts or not.

How has this been tested?

  • Trash or remove sticky from any sticky posts on your WordPress installation
  • Add a query loop block to the index in the site editor.
  • Set the Sticky post setting to "only".

Sample:

<!-- wp:query {"queryId":1,"query":{"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","sticky":"only","perPage":3,"inherit":false},"displayLayout":{"type":"list"}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->

<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->

<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->

<!-- wp:query-pagination-numbers /-->

<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination --></div>
<!-- /wp:query -->
  • Confirm that no posts are displaying in the editor. The message "No results found." is shown.
  • Save and view the front. Confirm that no posts are showing on the front.

Repeat the test with Inherit query from template enabled.
Now add a sticky post and make sure it still works correctly.

Problem 2

When the query block's Inherit query from template is not enabled, and Sticky posts is set to include,
the sticky posts are:

  1. Not displayed in the editor. This is incorrect.
  2. Displayed correctly on the homepage
  3. Also displayed on top of page 2, and so on in the paged result. This is incorrect.

The PR so far only solves this for the front.

How has this been tested?

  1. Make sure your installation has sticky posts
  2. Add a query loop block with a query pagination block to the index in the site editor.
  3. Save and view the front.
  4. Note which posts are showing on the first page, and navigate to page 2 or higher.
  5. Confirm that the sticky posts are not showing on page 2 or higher.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

&& empty( get_option( 'sticky_posts' ) ) ) {
return '';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to test if this also needs to include post type 😁

// Do not display duplicate sticky posts in the paged result.
if ( $page > 1 && is_sticky() ) {
continue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a solution. But I don't like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant