Browse Source

Posts: sticky posts on page 1 only + 100px between posts

- A custom Query Loop block (inherit:false, e.g. /desk/posts) prepends sticky posts
  to EVERY page because the block query never sets ignore_sticky_posts. Add a
  query_loop_block_query_vars filter that, on pages after the first, drops the
  stickies + sets ignore_sticky_posts — pinning them to page 1 only. Scoped to
  custom queries so the inherit:true search/archive blocks are untouched.
- 100px spacing between the full posts on /desk/posts (body.page-id-3919).
windhamdavid 2 weeks ago
parent
commit
9d0f638619
3 changed files with 31 additions and 0 deletions
  1. 26 0
      functions.php
  2. 5 0
      style.css
  3. 0 0
      v4-style.min.css

+ 26 - 0
functions.php

@@ -195,6 +195,32 @@ function dw_search_excerpt_highlight( $block_content, $block, $instance ) {
 	);
 	);
 }
 }
 add_filter( 'render_block_core/post-excerpt', 'dw_search_excerpt_highlight', 10, 3 );
 add_filter( 'render_block_core/post-excerpt', 'dw_search_excerpt_highlight', 10, 3 );
+
+/**
+ * Sticky posts on a custom Query Loop block (inherit:false — e.g. /desk/posts) get
+ * prepended to EVERY page, not just the first, because the block query never sets
+ * ignore_sticky_posts. Pin them to page 1 only: on later pages, stop prepending and
+ * drop the stickies (already shown up top on page 1). The inherit:true search/archive
+ * blocks handle stickies via the main query, so leave those alone.
+ */
+function dw_query_loop_sticky_first_page_only( $query, $block ) {
+	if ( ! empty( $block->context['query']['inherit'] ) ) {
+		return $query;
+	}
+	$query_id = isset( $block->context['queryId'] ) ? $block->context['queryId'] : 0;
+	$key      = 'query-' . $query_id . '-page';
+	$page     = empty( $_GET[ $key ] ) ? 1 : absint( $_GET[ $key ] );
+	if ( $page > 1 ) {
+		$sticky = get_option( 'sticky_posts' );
+		if ( ! empty( $sticky ) ) {
+			$query['post__not_in'] = array_merge( isset( $query['post__not_in'] ) ? $query['post__not_in'] : array(), $sticky );
+		}
+		$query['ignore_sticky_posts'] = 1;
+	}
+	return $query;
+}
+add_filter( 'query_loop_block_query_vars', 'dw_query_loop_sticky_first_page_only', 10, 2 );
+
 function dw_scripts() {
 function dw_scripts() {
 	global $post;
 	global $post;
 	wp_enqueue_style( 'style-min', get_template_directory_uri() . '/v4-style.min.css', array(), filemtime( get_template_directory() . '/v4-style.min.css' ) );
 	wp_enqueue_style( 'style-min', get_template_directory_uri() . '/v4-style.min.css', array(), filemtime( get_template_directory() . '/v4-style.min.css' ) );

+ 5 - 0
style.css

@@ -1441,6 +1441,11 @@ body.search mark {
 .dw-til-link { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
 .dw-til-link { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
 .dw-til-snippet { margin: .35rem 0 0; color: #333; }
 .dw-til-snippet { margin: .35rem 0 0; color: #333; }
 /* ===== end search results two-column ===================================== */
 /* ===== end search results two-column ===================================== */
+/* /desk/posts ("The Scroll", page id 3919) — generous space between the full posts
+   in the block query loop. */
+body.page-id-3919 .wp-block-post-template > li + li {
+	margin-top: 100px;
+}
 /* Pagination — classic archives (.page-numbers from dw_paging_nav) + the block
 /* Pagination — classic archives (.page-numbers from dw_paging_nav) + the block
    query pagination (search/archive). Centered, de-Bootstrapped pill links. */
    query pagination (search/archive). Centered, de-Bootstrapped pill links. */
 .pagination,
 .pagination,

File diff suppressed because it is too large
+ 0 - 0
v4-style.min.css


Some files were not shown because too many files changed in this diff