@@ -302,13 +302,25 @@ function render_related_posts_block(array $attributes): string
302
302
// Encode the query attributes to JSON for the block template
303
303
$ query_json = wp_json_encode ($ attributes ['query_attributes ' ], JSON_UNESCAPED_SLASHES );
304
304
305
+ // Dynamically render link to News & Stories page
306
+ $ news_stories_url = '' ;
307
+ $ news_stories_page = (int ) get_option ('page_for_posts ' );
308
+
309
+ if ($ news_stories_page ) {
310
+ $ news_stories_url = get_permalink ($ news_stories_page );
311
+ }
312
+
313
+ $ see_all_link_group = !empty ($ news_stories_url ) ?
314
+ '<!-- wp:navigation-link {"label":" ' . __ ('See all posts ' , 'planet4-blocks ' ) . '","url":" ' . $ news_stories_url . '","className":"see-all-link"} /--> '
315
+ : '' ;
316
+
305
317
// Define the HTML output for the block
306
318
$ output = '<!-- wp:query ' . $ query_json . ' -->
307
319
<div class="wp-block-query posts-list p4-query-loop is-custom-layout-list"><!-- wp:group {"layout":{"type":"flex","justifyContent":"space-between"}} -->
308
320
<div class="wp-block-group related-posts-block"><!-- wp:heading {"lock":{"move":true}} -->
309
321
<h2 class="wp-block-heading"> ' . __ ('Related Posts ' , 'planet4-blocks ' ) . '</h2>
310
322
<!-- /wp:heading -->
311
- <!-- wp:navigation-link {"label":" ' . __ ( ' See all posts ' , ' planet4-blocks ' ) . '","url":"http://www.planet4.test/news-stories/","className":"see-all-link"} /-->
323
+ ' . $ see_all_link_group . '
312
324
</div>
313
325
<!-- /wp:group -->
314
326
<!-- wp:post-template {"lock":{"move":true,"remove":true}} -->
@@ -328,7 +340,8 @@ function render_related_posts_block(array $attributes): string
328
340
<!-- /wp:group --></div>
329
341
<!-- /wp:columns -->
330
342
<!-- /wp:post-template -->
331
- <!-- wp:navigation-link {"label":" ' . __ ('See all posts ' , 'planet4-blocks ' ) . '","url":"http://www.planet4.test/news-stories/","className":"see-all-link"} /--></div>
343
+ ' . $ see_all_link_group . '
344
+ </div>
332
345
<!-- /wp:query --> ' ;
333
346
334
347
return do_blocks ($ output );
0 commit comments