admin管理员组文章数量:1391934
I'm making a website for a small church. They would like to upload sermons to their site. I've looked for a WP plugin to do that, but none of them did exactly what they wanted. So, I'm making a plugin to do what they want.
I've made a page called 'sermons' that has a page template 'sermon archive'. That file will display the sermon archive. I'd like to have it so when they click on a sermon, it would go to sermon/my-sermon-name
(rather than sermon?name=my-sermon-name
). Is there a way to do that in WordPress?
Thanks!
I'm making a website for a small church. They would like to upload sermons to their site. I've looked for a WP plugin to do that, but none of them did exactly what they wanted. So, I'm making a plugin to do what they want.
I've made a page called 'sermons' that has a page template 'sermon archive'. That file will display the sermon archive. I'd like to have it so when they click on a sermon, it would go to sermon/my-sermon-name
(rather than sermon?name=my-sermon-name
). Is there a way to do that in WordPress?
Thanks!
Share Improve this question asked Oct 22, 2012 at 12:35 CalebCaleb 1335 bronze badges 2- How are you storing sermons? As a CPT probably? – Mridul Aggarwal Commented Oct 22, 2012 at 12:47
- @Mridul Aggarwal I'm uploading them, and then storing the url, name, speaker, date, etc in a database (not created by WP). – Caleb Commented Oct 22, 2012 at 12:49
2 Answers
Reset to default 1You have to either work it out with the WP_Rewrite class or add this to the .htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^sermon/(.*)/ /sermon?name=$1 [L]
UPDATE
Forgot to mention that the htaccess code is supposed to be above the wordpress generated htaccess code
I got my answer from this page.
The final code:
add_action('init','yoursite_init');
function yoursite_init() {
global $wp,$wp_rewrite;
$wp->add_query_var('sermon_name');
$wp_rewrite->add_rule('sermon/([^/]+)/?', 'index.php?pagename=sermons&sermon_name=$matches[1]', 'top');
}
Thanks!
本文标签: pluginsHow can I pass a variable to a page with a SEF url
版权声明:本文标题:plugins - How can I pass a variable to a page with a SEF url? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744710666a2621109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论