markdown WordPress PHP函数预处理树枝的菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown WordPress PHP函数预处理树枝的菜单相关的知识,希望对你有一定的参考价值。
## Basic Version
```php
function preprocess_wp_menu_for_twig($orig_menu) {
$temp_array = [];
for($i = 0; $i < count($orig_menu); $i++) {
if( $orig_menu[$i]->children) {
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;
}
}
$primary_menu = new TimberMenu('primary');
preprocess_wp_menu_for_twig($primary_menu->items);
$context['primary_menu'] = $primary_menu;
```
## Object Oriented Version
```php
public function preprocess_wp_menu_for_twig($orig_menu) {
$temp_array = [];
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;
}
}
function add_to_context( $context ) {
...
//Add menus to context
$primary_menu = new TimberMenu('primary');
$this->preprocess_wp_menu_for_twig($primary_menu->items);
$context['primary_menu'] = $primary_menu;
...
}
```
以上是关于markdown WordPress PHP函数预处理树枝的菜单的主要内容,如果未能解决你的问题,请参考以下文章
markdown [wordpress:note] WordPress - 博客CMS由php。 #php #wordpress #cms
markdown PHP包含在Wordpress中
markdown 设置PHP CodeSniffer和WordPress标准
markdown 链接,片段,提醒,收集点作为重新访问WordPress插件开发期间的笔记#WordPress #Plugin #PHP #Refere
markdown (Codelink.pro)教程快速参考[https://codelink.pro/blog/run-wordpress-locally-using-the-inbuilt-php-
markdown MAMPで“お使いのサーバーのPHPではWordPressに必要なMySQL拡张を利用できないようです。”