在WordPress文件之外使用WordPress功能的正确方法是什么?
-
-
您尝试使用哪些WP函数" WP之外",为什么?这两种方法仍然可以加载WP环境(尽管没有主题支持),因此您仍在*调用WP内部的函数.Which WP functions are you trying to use "outside of WP" and why? Either of these methods will still load the WP environment (albeit without theme support), so you're *still* invoking functions inside of WP.
- 0
- 2012-03-27
- EAMann
-
我试图了解两种方法之间的区别.我要做的是将wordpress主题与我的支持脚本集成在一起.因此将需要wordpress的页眉,页脚和循环以及对小部件和其他插件的一些支持I am trying to understand the difference between the 2 methods. What I will do is integrate the wordpress theme with my support script. so will need the header, footer and the loop from wordpress plus some support for widgets and other plugins
- 0
- 2012-03-27
- alhoseany
-
我真的怀疑这是您要执行的操作的方式……比尝试自举WordPress本身,还有更好的解决方案.I really doubt this is the way you want to do things ... there are better solutions than trying to bootstrap WordPress itself.
- 0
- 2012-03-27
- EAMann
-
我愿意征求建议,我正在寻找做事的最佳方法?将wordpress主题与外部Web应用程序集成的最佳方法是什么?I am wide open for suggestions, I am looking for the best way to do things? what is the best way to integrate wordpress theme with outside web application?
- 0
- 2012-03-28
- alhoseany
-
6 个回答
- 投票数
-
- 2012-03-27
文件之间没有什么区别.当您查看WordPress页面时,第一个文件是
index.php
.从本质上讲,它就是您的"方法1"define('WP_USE_THEMES', true); /** Loads the WordPress Environment and Template */ require ('./wp-blog-header.php');
博客头文件(将WordPress的其余部分排入队列)直接加载
wp-load.php
并启动WordPress本身.这是大多数wp-blog-header.php
:if ( !isset($wp_did_header) ) { $wp_did_header = true; require_once( dirname(__FILE__) . '/wp-load.php' ); wp(); require_once( ABSPATH . WPINC . '/template-loader.php' ); }
因此,两种方法之间的区别是...加载了什么.
方法1正是WordPress自行加载的方法(关闭主题除外).因此,如果您需要WordPress的 all ,并且要触发所有默认的挂钩/操作,请选择该路线.
方法2只是进一步的改进.它会加载所有WordPress,但不会调用
wp()
或调用模板加载器(由主题使用).方法2会更轻一些,但应该为您提供相同的功能.There's little difference between the files. When you view a WordPress page, the first file called is
index.php
. And it is, essentially, your "Method 1:"define('WP_USE_THEMES', true); /** Loads the WordPress Environment and Template */ require ('./wp-blog-header.php');
The blog header file (that queues up the rest of WordPress) loads
wp-load.php
directly and fires up WordPress itself. Here's most ofwp-blog-header.php
:if ( !isset($wp_did_header) ) { $wp_did_header = true; require_once( dirname(__FILE__) . '/wp-load.php' ); wp(); require_once( ABSPATH . WPINC . '/template-loader.php' ); }
So the difference between your two methods is ... what's loaded.
Method 1 is exactly what WordPress does to load itself (with the exception of turning themes off). So if you need all of WordPress and want to fire all of the default hooks/actions, go with that route.
Method 2 is just a further step down the line. It loads all of WordPress, but doesn't call
wp()
or invoke the template loader (used by themes). Method 2 will be a little lighter-weight, but should give you the same functionality.-
是否有图表或将所有这些文件映射出来的内容?我很久以前见过,但找不到.Is there a diagram or something that maps all these files out? I saw one long ago but I can't find it.
- 3
- 2015-06-12
- ninja08
-
- 2012-03-27
问题2的方法:
<?php define( 'WP_USE_THEMES', false ); // Don't load theme support functionality require( './wp-load.php' );
wp-load.php
是对WordPress所有功能的访问,仅此而已.第一行告诉WordPress不加载主题文件;也许文件对于您的要求是必需的,然后删除该行.Method 2 from your question:
<?php define( 'WP_USE_THEMES', false ); // Don't load theme support functionality require( './wp-load.php' );
wp-load.php
is the access to all functions of WordPress, that's all. The first line tells WordPress to load not the Theme files; maybe the files are necessary for your requirements, then remove the line.-
第一行甚至意味着什么?what does that first line even means ?
- 1
- 2012-03-27
- Sagive SEO
-
第一行告诉WordPress不要加载其所有主题支持功能.基本上,加载较少的文件.The first line tells WordPress not to load all of its theme support functionality. Basically, load fewer files.
- 8
- 2012-03-27
- EAMann
-
第一行只需要第一种方法吗?Is the first line needed only for the first method?
- 0
- 2014-10-05
- mcont
-
-
- 2015-10-27
有时加载主题的functions.php可能会给您带来一些麻烦.它破坏了我另一页的html.这就是我所做的并解决了我的问题:
define('STYLESHEETPATH', ''); define('TEMPLATEPATH', ''); require_once(RAIZ_WORDPRESS."/wp-load.php");
Sometimes loading the functions.php of the theme can cause you some trouble. It was breaking the html of my other page. So that's what I did and solved my problem:
define('STYLESHEETPATH', ''); define('TEMPLATEPATH', ''); require_once(RAIZ_WORDPRESS."/wp-load.php");
-
- 2015-12-14
@ninja08
我们可以使用xDebugphp扩展来分析脚本.
只需从行首删除
;xdebug.profiler_enable = 1
,即可在您的php.ini
文件中启用;
并在重新启动apache服务器并运行您的wordpress站点后,现在在您的xampp服务器的tmp目录中创建了一个文件.="nofollownoreferrer"> WincachGrind 应用程序.现在您可以看到脚本的地图
@ninja08
We can use xDebug php extension to analyze an script.
just enable
;xdebug.profiler_enable = 1
in yourphp.ini
file by removing;
from first of line and after this restart apache server and run your wordpress site ...now a file created in tmp directory of your xampp server ..open this file with WincachGrind application.now you can see a map of your script
-
您应该已经在ninja08下面的评论中添加了此内容.现在这是一个错误的答案.You should have added this in the comment below ninja08. this is now an incorrect answer.
- 0
- 2015-12-15
- alhoseany
-
@alhoseany是的..我现在...但是我没有足够的声誉...然后我决定这样做.@alhoseany yes..i now it... but i dont have enough reputation...and then i decide to do this.
- 2
- 2015-12-15
- Mostafa
-
- 2020-05-07
您不必调用整个主题即可使用功能,只需在wordpress目录中使用wp-load.php的位置即可.
<?php require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php'); ?>
You don't have to call the entire theme to use functions, just use the location for wp-load.php in wordpress directory.
<?php require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php'); ?>
我了解了两种在WordPress文件外部初始化WordPress功能的方法,因此我们可以在WordPress博客之外的任何页面或网站上使用这些功能.
这2种方法中哪一种是正确的?如果两种方法都正确,每种方法的用例是什么?使用一种方法或另一种方法有什么区别?
方法1:
方法2: