简体   繁体   中英

Including WordPress navigation in external (non-WP) scripts

I posted this to StackExhange last Friday and got no responses so I thought I'd try here?

I have a client who is adding a WordPress site as a public non-logged-in front-end to an app.

Logged in customers will be using a couple hundred scripts for specialized data management relating to their golf game. For consistency's sake we would like to be able to include the live navigation from the WordPress site. Is there a discreet script that can be included with the CSS to accomplish this? If not has anyone done this before or seen information on it?

Obviously I can use the WP tables to emulate the menuing if needed but it would be nice to just gank the WP nav...

There are two (in my opinion) easy ways:

  • Create a template on your WP installation you fetch using your server-side language or AJAX that displays navigation only
  • Download your webpage programmatically and filter your navigation out

I would go for first approach. The easiest way is to make your own php file for your navigation, and get that file (http://www.example.com/wp-content/themes/your-theme/navigation.php). This should display the HTML content.

Now, using your server-side language you can simply "echo" the response, like so:

<?php
$ch = curl_init('http://www.example.com/wp-content/themes/your-theme/navigation.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

curl_close($ch);

echo $response; // your menu
?>

Unfortunately, there's is no easy way to get the CSS too. You could split the CSS for the navigation too and include that.

<link rel="stylesheet" type="text/css" href="http://www.example.com/wp-content/themes/your-theme/css/navigation.css" />

It's just a matter of creativity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM