markdown 用于预处理字段的WordPress自定义PHP函数在Twig模板中使用之前

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 用于预处理字段的WordPress自定义PHP函数在Twig模板中使用之前相关的知识,希望对你有一定的参考价值。

```php
/**
 * Converts the output of a WP ACF image field into a variable 
 * ready for our card srcset twig template 
 * 
 * I'm noticing now that Jason has done something very similar
 * but fancier just below... ¯\_(ツ)_/¯ 
 */
function acf_image_to_srcset($acf_image_field, $wp_image_size, $sizes = '100vw') {
  $temp['srcset'] = wp_get_attachment_image_srcset( $acf_image_field['id'], $wp_image_size );
  $temp['alt'] = $acf_image_field['alt'];
  $temp['src'] = $acf_image_field['url'];
  $temp['caption'] = $acf_image_field['caption'];
  $temp['sizes'] = $sizes;

  return $temp;
}
```



This one actually goes into RadicatiSite.php, since that's where the add_to_context function lives:
```php
public function preprocess_wp_menu_for_twig($orig_menu) {
  for($i = 0; $i < count($orig_menu); $i++) {
    if( $orig_menu[$i]->children) {
      $this->preprocess_wp_menu_for_twig($orig_menu[$i]->children);
    }
    $orig_menu[$i]->title = $orig_menu[$i]->name;
    $orig_menu[$i]->link = $orig_menu[$i]->url;
  }
  return $orig_menu;
}
```

以上是关于markdown 用于预处理字段的WordPress自定义PHP函数在Twig模板中使用之前的主要内容,如果未能解决你的问题,请参考以下文章

markdown 用于处理请求的有用命令

markdown 用于处理请求的有用命令

php 儿童主题的Wordpres功能

php 查询帖子类型wordpres

php Wordpres检索密码电子邮件

PHP Wordpres,查询最新帖子