【问题标题】:edit via function php the gallery in posts created with gutenberg通过函数 php 编辑使用古腾堡创建的帖子中的画廊
【发布时间】:2019-08-19 11:48:32
【问题描述】:

我正在尝试修改古腾堡通过函数 php 提供的画廊的 html 输出...但我不能。

你如何拦截和修改自己?

这是原文:

<ul="wp-block-gallery columns-2 is-cropped">
  <li class="blocks-gallery-item">....</li>
  <li class="blocks-gallery-item">....</li>
</ul>

我想根据列数对其进行更改以使其适应我的开发框架...

<div class="grid-x">
   <div class="box-50">...</div>
   <div class="box-50">...</div>
</div>

存在如何通过function.php更改它??

【问题讨论】:

  • 您是否检查过 wordpress 中是否存在过滤器?
  • 是的,但是我什么都不懂,因为他们玩弄 js 和 php,我总是迷失自我……如果能恢复 php 中的值并进行更改,那就太好了替换。

标签: php wordpress-gutenberg


【解决方案1】:

解决方案:

通过函数 php 覆盖 Wp gutenberg html 输出的示例:

add_filter( 'render_block', 'GutenGallery' , 10, 2 );

  function GutenGallery( $block_content, $block )
  {

    if ( 'core/gallery' !== $block['blockName'] || ! isset( $block['attrs']['ids'] ) )
    {
      return $block_content;
    }

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

    foreach( (array) $block['attrs']['ids'] as $id ) {

      if( $col == "1" || !$col)
      {
        $li .= sprintf( '<div class="box-[50-50-100]"><div class="autocrop radius-medium" style="height:300px;">%s</div></div>', wp_get_attachment_image( $id, 'large' ) );
      }
      elseif ($col == "2" )
      {
        $li .= sprintf( '<div class="box-[50-50-100]"><div class="autocrop radius-medium" style="height:300px;">%s</div></div>', wp_get_attachment_image( $id, 'large' ) );
      }
      elseif ($col == "3" )
      {
        $li .= sprintf( '<div class="box-[33-33-100]"><div class="autocrop radius-medium" style="height:300px;">%s</div></div>', wp_get_attachment_image( $id, 'large' ) );
      }
      elseif ($col >= "4" )
      {
        $li .= sprintf( '<div class="box-[25-25-50]"><div class="autocrop radius-medium" style="height:300px;">%s</div></div>', wp_get_attachment_image( $id, 'large' ) );
      }

    }
    return sprintf( '<div class="grid-x gap-20">%s</div>', $li );

  }

(框是我框架上使用的网格kimera

谢谢大家;)

【讨论】:

    猜你喜欢
    • 2022-01-09
    • 1970-01-01
    • 2019-10-04
    • 2019-02-11
    • 2018-06-20
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多