Exemple #1
0
 public static function editQuery($posts, WP_Query $wp_query)
 {
     if (!self::$_fired) {
         foreach (self::$_pages as $page) {
             if ($wp_query->get($page['query_var']) == 1) {
                 if (!empty($page['headerCallback'])) {
                     self::$_fired = true;
                     call_user_func($page['headerCallback']);
                 }
                 //create a fake post
                 $post = new stdClass();
                 $post->post_author = 1;
                 $post->post_name = $page_slug;
                 $post->guid = get_bloginfo('wpurl' . '/' . $page['slug']);
                 $post->post_title = self::_showPageTitle($page['title']);
                 //put your custom content here
                 $post->post_content = 'Content Placeholder';
                 //just needs to be a number - negatives are fine
                 $post->ID = -42;
                 $post->post_status = 'static';
                 $post->comment_status = 'closed';
                 $post->ping_status = 'closed';
                 $post->comment_count = 0;
                 //dates may need to be overwritten if you have a "recent posts" widget or similar - set to whatever you want
                 $post->post_date = current_time('mysql');
                 $post->post_date_gmt = current_time('mysql', 1);
                 $posts = NULL;
                 $posts[] = $post;
                 $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;
                 add_filter('template_include', array(get_class(), 'overrideBaseTemplate'));
                 break;
             }
         }
     }
     return $posts;
 }