1414 * Note that this function is hooked into the after_setup_theme hook, which
1515 * runs before the init hook. The init hook is too late for some features, such
1616 * as indicating support for post thumbnails.
17+ *
18+ * @return void
1719 */
1820 function osi_setup () {
1921 /*
@@ -114,6 +116,8 @@ function osi_setup() {
114116
115117/**
116118 * Register sidebars and widgets
119+ *
120+ * @return void
117121 */
118122function osi_widgets_init () {
119123 // Sidebars
@@ -168,7 +172,8 @@ function osi_widgets_init() {
168172 *
169173 * Priority 0 to make it available to lower priority callbacks.
170174 *
171- * @global int $content_width
175+ * @global int $content_width Content width to set.
176+ * @return void
172177 */
173178function osi_content_width () {
174179 $ GLOBALS ['content_width ' ] = apply_filters ( 'osi_content_width ' , 640 );
@@ -177,6 +182,8 @@ function osi_content_width() {
177182
178183/**
179184 * Add a reusable block admin menu link for easy administration.
185+ *
186+ * @return void
180187 */
181188function osi_reusable_blocks_admin_menu (): void {
182189 add_theme_page (
@@ -192,6 +199,8 @@ function osi_reusable_blocks_admin_menu(): void {
192199
193200/**
194201 * Enqueue scripts and styles.
202+ *
203+ * @return void
195204 */
196205function osi_scripts () {
197206 wp_enqueue_style (
@@ -226,7 +235,11 @@ function osi_scripts() {
226235}
227236add_action ( 'wp_enqueue_scripts ' , 'osi_scripts ' );
228237
229- /** Frontend Inline Styles **/
238+ /**
239+ * Add inline styles to the frontend.
240+ *
241+ * @return void
242+ */
230243function osi_inline_styles () {
231244 wp_add_inline_style ( 'osi-style ' , osi_palette_css () );
232245 wp_add_inline_style ( 'osi-style ' , osi_gradient_css () );
@@ -235,7 +248,11 @@ function osi_inline_styles() {
235248}
236249add_action ( 'wp_enqueue_scripts ' , 'osi_inline_styles ' , 100 ); // prioritize as last
237250
238- /** Block Editor Styles **/
251+ /**
252+ * Add block editor assets.
253+ *
254+ * @return void
255+ */
239256function osi_add_block_editor_assets () {
240257 wp_enqueue_style ( 'editor-styles ' , get_template_directory_uri () . '/assets/css/editor-style.css ' , '' , 1 );
241258 wp_add_inline_style ( 'editor-styles ' , osi_palette_css () );
@@ -316,9 +333,11 @@ function osi_add_block_editor_assets() {
316333
317334/**
318335 * Register the "Footer - Above credits" sidebar.
336+ *
337+ * @return void
319338 */
320339function register_footer_above_sidebar () {
321- register_sidebar (
340+ register_sidebar (
322341 array (
323342 'name ' => esc_html__ ( 'Footer - Above Credits ' , 'osi ' ),
324343 'id ' => 'footer-above-credits ' ,
@@ -327,7 +346,51 @@ function register_footer_above_sidebar() {
327346 'after_widget ' => '</div> ' ,
328347 'before_title ' => '<h2 class="widget-title"> ' ,
329348 'after_title ' => '</h2> ' ,
330- )
349+ )
331350 );
332351}
333- add_action ('widgets_init ' , 'register_footer_above_sidebar ' );
352+ add_action ( 'widgets_init ' , 'register_footer_above_sidebar ' );
353+
354+ /**
355+ * Adjust the 'blog' (post archive) to show a different number of posts on the first page.
356+ *
357+ * @param WP_Query $query WordPress Query object.
358+ *
359+ * @return void
360+ */
361+ function osi_query_offset ( WP_Query &$ query ) {
362+ if ( ! ( $ query ->is_blog () || is_main_query () ) || is_admin () || is_front_page () || is_archive () || is_404 () ) {
363+ return ;
364+ }
365+
366+ $ offset = -1 ;
367+ $ ppp = get_option ( 'posts_per_page ' );
368+
369+ if ( $ query ->is_paged ) {
370+ // Manually determine page query offset (offset + current page (minus one) x posts per page)
371+ $ page_offset = $ offset + ( ( $ query ->query_vars ['paged ' ] - 1 ) * $ ppp );
372+ // Apply adjust page offset
373+ $ query ->set ( 'offset ' , $ page_offset );
374+ } else {
375+ // This is the first page. Set a different number for posts per page
376+ $ query ->set ( 'posts_per_page ' , $ offset + $ ppp );
377+ }
378+ }
379+ add_action ( 'pre_get_posts ' , 'osi_query_offset ' , 1 );
380+
381+ /**
382+ * Adjust the pagination offset.
383+ *
384+ * @param integer $found_posts The number of found posts.
385+ * @param WP_Query $query WordPress Query object.
386+ *
387+ * @return integer Adjusted number of found posts.
388+ */
389+ function osi_adjust_offset_pagination ( int $ found_posts , WP_Query $ query ) {
390+ $ offset = -1 ;
391+ if ( $ query ->is_blog () && is_main_query () && ! is_admin () && ! $ query ->is_front_page () ) {
392+ return $ found_posts - $ offset ;
393+ }
394+ return $ found_posts ;
395+ }
396+ add_filter ( 'found_posts ' , 'osi_adjust_offset_pagination ' , 1 , 2 );
0 commit comments