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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
* @return string Returns the output of the query, structured using the layout defined by the block's inner blocks.
*/
function render_block_core_post_template( $attributes, $content, $block ) {

// Return early if sticky posts are set to only, but there are no sticky posts.
if ( isset( $block->context['query']['sticky'] )
&& 'only' === $block->context['query']['sticky']
&& 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 😁

$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];

Expand Down Expand Up @@ -52,6 +60,10 @@ function render_block_core_post_template( $attributes, $content, $block ) {
$content = '';
while ( $query->have_posts() ) {
$query->the_post();
// 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.

$block_content = (
new WP_Block(
$block->parsed_block,
Expand Down