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.
-
This question is a little bit vague. Could you clarify please?– John P BlochSep 27, 2010 at 16:00
-
What I mean, I want to call a template file without assigning that you a page.– Mild FuzzSep 27, 2010 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 FuzzSep 27, 2010 at 16:40
1 Answer
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' );
-
Does this mean I still need to have a page in the pages DB in order to have a nav link? Sep 28, 2010 at 8:43
-
1Yes, 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.– sorich87Sep 28, 2010 at 10:20