简体   繁体   English

在外部(非WP)脚本中包括WordPress导航

[英]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? 我上周五将其发布到StackExhange,但没有任何回应,所以我想在这里尝试?

I have a client who is adding a WordPress site as a public non-logged-in front-end to an app. 我有一个客户正在将WordPress网站作为公共未登录前端添加到应用程序。

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. 为了保持一致性,我们希望能够包含来自WordPress网站的实时导航。 Is there a discreet script that can be included with the CSS to accomplish this? CSS可以包含一个谨慎的脚本来完成此操作吗? 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... 显然,如果需要,我可以使用WP表来模拟菜单,但是只要将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 使用显示导航的服务器端语言或AJAX在您获取的WP安装上创建模板
  • 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). 最简单的方法是制作自己的php文件进行导航,并获取该文件(http://www.example.com/wp-content/themes/your-theme/navigation.php)。 This should display the HTML content. 这应该显示HTML内容。

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. 不幸的是,也没有简单的方法来获取CSS。 You could split the CSS for the navigation too and include that. 您也可以为导航拆分CSS并将其包括在内。

<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. 这只是创造力的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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