将网格的内容布局获取到 gutenber 博客中

Get content layouts of grid into gutenber blog

基于previous的开发,我编写了一个小代码来修改古腾伯网格。但是我不知道如何检索列的内容并将其重新应用于上下文。

进入funciton.php

  // Change WordPress gutenberg grid
  add_filter( 'render_block', 'GutenGrid' , 10, 2 );
  function GutenGrid( $block_content, $block )
  {

    if ( $block['blockName'] !== 'core/columns' )
    {
      return $block_content;
    }

    $col = $block['attrs']['columns'];

    $boxes = '';

    // foreach( (array) $block['attrs']['ids'] as $id ) {
    for ($c = 0; $c <= $col-1; $c++) {


     if ($col == "3" )
      {
        $boxes .= '<div class="box-[33-33-100]"><div><p>type3col</p>'. content ?? .'</div></div>' ;
      }
      elseif ($col == "4" )
      {
        $boxes .= '<div class="box-[25-25-50]"><div><p>type4col</p>'. content ?? .'</div></div>' ;
      }
      elseif ($col == "5" )
      {
        $boxes .= '<div class="box-[20-20-50]"><div><p>type5col</p>'. content ?? .'</div></div>' ;
      }
      elseif ($col >= "6" )
      {
        $boxes .= '<div class="box-[15-15-50]"><div><p>type6col</p>'. content ?? .'</div></div>' ;
      }
      else {
        $boxes .= '<div class="box-[50-50-100]"><div><p>type1&2col</p>'. content ?? .'</div></div>' ;
      }

    }

    $output = '<p>GRID REWRITED:</p><div class="grid-x gap-30">'.$boxes.'</div>';

    return sprintf( $output, $boxes );

  }

可以帮我吗?

已解决:

      // Change WordPress gutenberg grid
  add_filter( 'render_block', 'GutenGrid' , 10, 2 );
  function GutenGrid( $block_content, $block )
  {

    if ( $block['blockName'] !== 'core/columns' )
    {
      return $block_content;
    }

    $col = $block['attrs']['columns'];
    $content = $block['innerBlocks'][0]['innerBlocks'][0]['innerContent'];

    $boxes = '';

    // foreach( (array) $block['attrs']['ids'] as $id ) {
    for ($c = 0; $c <= $col-1; $c++) {


     if ($col == "3" )
      {
        $boxes .= '<div class="box-[33-33-100]"><div>'. $block['innerBlocks'][$c]['innerBlocks'][0]['innerContent'][0] .'</div></div>' ;
      }
      elseif ($col == "4" )
      {
        $boxes .= '<div class="box-[25-25-50]"><div>'. $block['innerBlocks'][$c]['innerBlocks'][0]['innerContent'][0] .'</div></div>' ;
      }
      elseif ($col == "5" )
      {
        $boxes .= '<div class="box-[20-20-50]"><div>'. $block['innerBlocks'][$c]['innerBlocks'][0]['innerContent'][0] .'</div></div>' ;
      }
      elseif ($col >= "6" )
      {
        $boxes .= '<div class="box-[15-15-50]"><div>'. $block['innerBlocks'][$c]['innerBlocks'][0]['innerContent'][0] .'</div></div>' ;
      }
      else {
        $boxes .= '<div class="box-[50-50-100]"><div>'. $block['innerBlocks'][$c]['innerBlocks'][0]['innerContent'][0] .'</div></div>' ;
      }

    }

    $output = '<p>GRID REWRITED:</p><div class="grid-x gap-30">'.$boxes.'</div>';

    return sprintf( $output, $boxes );

  }