我可以在新的 php 页面中使用 WordPress 主题吗?
我正在建立一个需要包含一些注册和博客功能的网站。 Wordpress 似乎非常适合该应用程序的这一部分,因此我开始尝试它。 我看到很多有关创建自定义主题的教程,因此我认为这不会成为问题。
我不知道如何处理我网站的其余部分。 我将有其他非博客相关的 php 页面来访问数据库等。我看到 wordpress 具有静态内容通用页面的功能,但这些需要编码为 PHP 页面。 我只是找不到一种方法将 WordPress 主题应用于 WordPress 之外的其他 php 页面。 我希望只是做类似的事情
wp_header();
blah blah
wp_sidebar();
blah blah
wp_footer();
,但我并没有真正看到任何关于如何完成此操作的示例或文档。 我是否遗漏了重要的文档?
编辑:答案本质上是从主题复制并粘贴一个文件,并添加一个关键的附加内容:
require( dirname(__FILE__) . 'path_to_wp_root/wp-load.php');
设置 WordPress 环境并允许我调用 get_header()、get_sidebar()、get_footer() 等。
I'm putting together a web site that needed to include some signup and blogging capability. Wordpress seems to be a perfect fit for that portion of the app, so I've started experimenting with it. I see plenty of tutorials on creating custom themes so I don't expect that to be a problem.
What I'm not able to figure out is what to do with the rest of my site. I will have other non-blogging related php pages that will access a database, etc. I see that wordpress has a capability for generic pages of static content, but these would need to be coded PHP pages. I just can't find a way of having the wordpress theme apply to other php pages outside of wordpress. I was hoping of just doing something like
wp_header();
blah blah
wp_sidebar();
blah blah
wp_footer();
but I'm not really seeing any examples or documentation on how this might be done. Am I missing a key piece of documentation?
EDIT: The answer is to essentially copy and paste a file from the theme, with one crucial addition:
require( dirname(__FILE__) . 'path_to_wp_root/wp-load.php');
That sets up the wordpress environment and allows me to call get_header(), get_sidebar(), get_footer(), etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
通常,“是”。
一个设计良好的 WordPress 主题主要使用 CSS/样式表进行显示,您的假设是正确的:查看有关主题设计/模板设计的“Codex”(http://codex.wordpress.org/Stepping_Into_Templates)。
本质上,您可以将您的设计基于一些当前的主题文件,但忽略“循环”。
Generally, "yes".
A well-designed WordPress theme uses mostly CSS/Stylesheets for display, and you are correct in your assumptions: Look through the "Codex" about Theme Design / Template Design (http://codex.wordpress.org/Stepping_Into_Templates).
Essentially you could base your design on some of the current theme files, but leave out "the loop".
我认为你真正想做的是将 wp-load.php 包含在 php 文件的顶部。 这将使您可以访问所有 WordPress 函数(wp-header()、wp-footer() 等)。
I think what you really want to do is include wp-load.php at the top of your php file. This will give you access to all the wordpress functions (wp-header(), wp-footer(), etc).
wordpress 中有页面。 每个页面都可以有自己的内容和模板,并且仍然是整个 WordPress 网站的一部分。 我的意思是,如果您愿意,它将共享页眉和页脚,并将共享您在两者中包含的 css 和 javascript。
了解有关页面和页面模板的更多信息
wordpress has pages in it. each page can have its own content and its own template and still be part of the whole wordpress site. i mean it will share the header and the footer if you want and will share the css and javascript that you include in both.
for more information on pages and pages templates
你应该做的是将其他非博客相关的 php 页面开发为 WordPress 插件。 网上有很多关于如何执行此操作的参考资料,例如:
http://www.tutorialized。 com/view/tutorial/Creating-a-Custom-Wordpress-Plugin-from-Scratch/41834
What you should do is develop your other non-blogging related php pages as a wordpress plugin. There are plenty of references online on how to do this, for example:
http://www.tutorialized.com/view/tutorial/Creating-a-Custom-Wordpress-Plugin-from-Scratch/41834
另一种选择是使用 Wordpress 作为网站上所有内容的 CMS。 这越来越流行,因为如今 WordPress 在非博客方面非常擅长。
Another option is to use Wordpress as the CMS for all content on your site. This is increasingly becoming popular, as Wordpress is quite good at non-blog-things these days.
方便在外使用wordpress功能
easy to use wordpress function outside