Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add route to return rendered html of a single menu#27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Underdawgq wants to merge9 commits intounfulvio:master
base:master
Choose a base branch
Loading
fromUnderdawgq:master

Conversation

@Underdawgq
Copy link

I did not test the code for v1 of the REST API.

Also made a correction to the get_menu() function the $rest_url was getting the api namespace instead of the plugin name space
Didn't test the REST API v1 version of this.
…endered in html from the location for the API v1. Also changed "render_html" to "html" in the json output for API v1.Code hasn't been tested
@fahrradflucht
Copy link
Contributor

fahrradflucht commentedNov 21, 2016
edited
Loading

@Underdawgq Could you explain what this does and how do you indent someone to use it?

@Underdawgq
Copy link
Author

Instead of returning the menu as a tree these routes return the menu in html. If someone wanted to simply mirror a menu from one WordPress site to another this is much easier than setting up a loop to transform the tree into html.

So if site B wanted the same menu as site A then all they would have to do is edit the theme for site B from something like this:
wp_nav_menu( array ( 'menu_class' => 'nav-menu', 'menu' => 'menu-slug' ) );

to use something like:
// Get json file content
$siteAmenu_jsoncontent=file_get_contents('http://www.siteA.com/wp-json/wp-api-menus/v2/menu-html/menu-slug');
//Decode json content into an array
$siteAmenu_json=json_decode($siteAmenu_jsoncontent, true);
// Optional: Replace generic id and/or class attributes with id and class attributes for this specific menu
$siteAmenu_json['html']=str_replace('ul', 'ul', $siteAmenu_json['html']);
// Display menu on screen/in browser
echo $siteAmenu_json['html'];

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Underdawgq@fahrradflucht

[8]ページ先頭

©2009-2025 Movatter.jp