Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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');
share|improve this answer
    
Thanks for the updates, after a long search I did exactly same as above just 3hour before. –  coderex Mar 27 '11 at 15:31
    
Was trying to figure out how to do something like this and thanks to this answer it is now solved –  xLRDxREVENGEx Jun 16 '11 at 1:11
    
@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? –  internetross Aug 24 '12 at 0:50

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?

share|improve this answer
    
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 '11 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 '11 at 13:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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