Skip to content

Commit

Permalink
Pass the ID to the get_permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Sep 12, 2023
1 parent 96cfeb5 commit a3350d8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/block-library/src/table-of-contents/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ function block_core_table_of_contents_build_headings_tree( $headings ) {
* @since 6.4.0
*
* @param array $tree An array of nested headings.
* @param array $args Additional arguments used for building the list.
*
* @return string $list A list of Table of Content items.
*/
function block_core_table_of_contents_build_list( $tree ) {
function block_core_table_of_contents_build_list( $tree, $args ) {
$list = '';
$permalink = get_permalink();
$permalink = get_permalink( $args['postId'] );

foreach ( $tree as $item ) {
$heading = $item['heading'];
$children = isset( $item['children'] ) ? '<ol>' . block_core_table_of_contents_build_list( $item['children'] ) . '</ol>' : '';
$children = isset( $item['children'] ) ? '<ol>' . block_core_table_of_contents_build_list( $item['children'], $args ) . '</ol>' : '';

if ( ! empty( $heading['link'] ) ) {
$pagelink = ! empty( $heading['page'] ) ? add_query_arg( 'page', $heading['page'], $permalink ) : $permalink;
Expand Down Expand Up @@ -179,6 +181,6 @@ function render_block_core_table_of_contents( $attributes, $content, $block ) {
return sprintf(
'<nav %1$s><ol>%2$s</ol></nav>',
get_block_wrapper_attributes(),
block_core_table_of_contents_build_list( $tree )
block_core_table_of_contents_build_list( $tree, array( 'postId' => $block->context['postId'] ) )
);
}

0 comments on commit a3350d8

Please sign in to comment.