1

I want to load some of the pages(not wordpress page, a template file other than wordpress's default template file) according to the url came on the address bar.

for instance, I have page in my template file ie my_account.php to show my profile pic and other informations from to my wordpress pofile. and it is placed in my defaut theme folder

/themes/mytheme/my_account.php

When the url is http://mysite/MyAccount/ then I need to load the above page. Something like if http://mysite/register/ then load the register.php from my theme folder.

I'm using custome permalinks option. http://mysite/hello_world_post/

So How can I configure and load the template according to the url, how to controll this by using a plugin.

2 Answers 2

2

You should be able to use template_redirect. I haven't tested it though, should be something like this.

function page_redirect() {
    if ($_SERVER['REQUEST_URI'] == 'your_url')  {

        require(TEMPLATEPATH . '/mY-account.php');

    }
}
add_action('template_redirect', 'page_redirect');
3
  • Thanks for the updates, after a long search I did exactly same as above just 3hour before.
    – coderex
    Mar 27, 2011 at 15:31
  • Was trying to figure out how to do something like this and thanks to this answer it is now solved Jun 16, 2011 at 1:11
  • 1
    @coderex et al wouldn't you have to disable WordPress from flagging this unknown URL (within your existing rewrite rules) and returning 404? eg, by adding new query vars or hijacking $wp_query->is_404 . or were you successful otherwise? Aug 24, 2012 at 0:50
1

See this: http://codex.wordpress.org/Pages#Templates_by_page-ID_or_page-Slug

The easiest is by slug. For example if your http://mysite/register/ slug is register then create a custom page template page-register.php.

BTW, I didn't know you can use _ for permalink? Plugin?

2
  • In this case I need to create a page from my admin area, But I don't want to do that. Is there any method to achieve this??
    – coderex
    Mar 26, 2011 at 13:02
  • Just create a blank Pages. Put in title and slug with no content. It will load the template. BTW, if you still don't want to create from admin, I think there's a plugin called Fake Page.
    – zeo
    Mar 26, 2011 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.