Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'the_posts', 'generate_contact_page', -10 );
- function generate_contact_page( $posts ) {
- global $wp, $wp_query;
- $url_slug = 'contact'; // URL slug of the contact page
- if ( ! defined( 'CONTACT_PAGE' ) && ( strtolower( $wp->request ) == $url_slug ) ) {
- // stop interferring with other $posts arrays on this page (only works if the sidebar is rendered *after* the main page)
- define( 'CONTACT_PAGE', true );
- // create a contact virtual page
- $post = new stdClass;
- $post->post_author = 1;
- $post->post_name = $url_slug;
- $post->guid = home_url() . '/' . $url_slug;
- $post->post_title = 'Contact page';
- $post->post_content = 'page template: contact.php';
- $post->ID = -999;
- $post->post_type = 'page';
- $post->post_status = 'static';
- $post->comment_status = 'closed';
- $post->ping_status = 'open';
- $post->comment_count = 0;
- $post->post_date = current_time( 'mysql' );
- $post->post_date_gmt = current_time( 'mysql', 1 );
- $posts = NULL;
- $posts[] = $post;
- // make wpQuery believe this is a real page too
- $wp_query->is_page = true;
- $wp_query->is_singular = true;
- $wp_query->is_home = false;
- $wp_query->is_archive = false;
- $wp_query->is_category = false;
- unset( $wp_query->query[ 'error' ] );
- $wp_query->query_vars[ 'error' ] = '';
- $wp_query->is_404 = false;
- }
- return $posts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement