基于Previous开发,我构建了一个小代码来修改gutenber网格...但是我不知道如何检索列的内容并将其重新应用于上下文。...< / p>
进入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 );
}
能帮我吗?
答案 0 :(得分:1)
已解决
// 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 );
}
该方法适用于所有内容,当前网格基于kimera