WordPress 包含自定义页面
我确信这是一个简单的问题。但是如何让 Wordpress 在启动时忽略加载页面或帖子的尝试,而是加载我的自定义页面呢?在 WordPress 引导过程中,何时决定要加载哪个 php 页面?
我将有以下网址:
bt.local/wp/ads/1
并且希望加载一个名为 ads.php 的 php 页面并使用 adid = 1 加载广告。
解决此问题的最佳方法是什么? (没有名为广告的帖子,也没有名为广告的页面)。
谢谢你!
KR
约瑟夫
I'm sure this is a simple question. But how do I get Wordpress at startup to ignore trying to load a Page or Post and instead load my custom page? When in the Wordpress bootstrap process is it decided which php-page is going to load?
I will have the following url:
bt.local/wp/ads/1
And would like a php-page called ads.php to be loaded and load the ad with adid = 1.
What's the best way to solve this? (there's no Post called ads and there's no Page called Ads).
Thank you!
KR
Josef
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 template_redirect 操作 - 例如:
编辑:
除此之外,您还需要一些新的重写规则来添加自定义网址 - 基本信息位于此处 http://codex.wordpress.org/Function_Reference/WP_Rewrite
您的规则可能看起来像这样:
这需要设置一个名为广告的“占位符”页面,此外您必须像这样注册新的查询 var
adid
:you can use the template_redirect action for that - example:
edit:
in addition to that you need some new rewrite rule to add your custom url - the basic information is here http://codex.wordpress.org/Function_Reference/WP_Rewrite
your rule could look something like that:
this needs a 'placeholder' page called ads to be setup and in addition to that you have to register your new query var
adid
like that:???
<?php include('custompage.php'); ?>
???