I am trying to include a special Archive page with my theme, right now I have a PHP file with
Template Name: Archives Template
at the top and I the user must create a blank archive POST PAGE and then select this as the template.
The content for creating the page is blank so nothing is added into the database for the page content. Is there anyway to make it where they do not have to do this?
To wit, this technically isn’t a ‘page’, however it’s a way to surface content using mod_rewrite. The goal here is to add a URI segment of foobar that will trigger a custom query, then include the specified template file.
Add a rewrite rule:
See the WP_Query documentation for more information about customizing the query string.
Register a new query var:
Force WP to select your page template:
Flush the rewrites by visiting Settings->Permalinks, then visit http://yourdomain.com/foobar
An additional remark to Brian Fegter’s answer. if you want to flush the rewrites rules programmatically instead of visiting Settings->Permalinks, you can use
flush_rewrite_rules()
.However, don’t put it on
init
hook, as the WordPress Codex strongly recommands. You can put bothflush_rewrite_rules()
method and thefoo_add_rewrite_rule()
onregister_activation_hook
.I was able to stop the
is_front_page()
andis_home()
functions from evaluating to true for my “fake” page by adding apre_get_posts
method