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.

This idea is just to protect certain sections of my theme from over-zealous clients. I would like to add pages, that exist in the front end and can be added to the menu (using wordpress 3.0 api) but the page NOT be present in the 'Pages' dialogue in the admin panel, and is thus not user editable.

share|improve this question
    
This question is a little bit vague. Could you clarify please? –  John P Bloch Sep 27 '10 at 16:00
    
What I mean, I want to call a template file without assigning that you a page. –  Mild Fuzz Sep 27 '10 at 16:39
    
For example, I have a section that lists venues. It is a loop based on the custom post type, 'Venus'. I have a template file with that loop, but in order to put that page in the navigation, I have to assign the template to a page. Can I avoid this? –  Mild Fuzz Sep 27 '10 at 16:40
add comment

1 Answer 1

up vote 3 down vote accepted

You can hook into template_redirect like this:

function custom_template_redirect() {
    global $wp;

    if ($wp->query_vars['pagename'] == 'my-page-slug') { // check the page slug
        status_header(200); // a 404 code will not be returned in the HTTP headers if the page does not exists

        include(TEMPLATEPATH . "/test.php"); // include the corresponding template
        die();
    }
}
add_action( 'template_redirect', 'custom_template_redirect' );
share|improve this answer
    
Does this mean I still need to have a page in the pages DB in order to have a nav link? –  Mild Fuzz Sep 28 '10 at 8:43
1  
Yes, you will need to have the page in the db, or you can hook into the filter 'wp_nav_menu_items' or "wp_nav_menu_{$menu->slug}_items" with a custom code to add the page in the nav. –  sorich87 Sep 28 '10 at 10:20
add comment

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.