Title: Including WordPress
Last modified: August 19, 2016

---

# Including WordPress

 *  [crispina](https://wordpress.org/support/users/crispina/)
 * (@crispina)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/including-wordpress/)
 * Hi,
 * I have created a .php file which runs several mysql functions, since I can’t 
   effectively add php code to a ‘page’ or ‘post’. I would really like this .php
   file to ‘include’ my wordpress theme (i.e. show the header, the sidebar, etc.).
   If I call include ‘header.php’ it can’t access bloginfo. If I call include ‘archive.
   php’ it can’t access get_header… How on earth do I do this?
 * Cheers,
    Crispin

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [dagon-design](https://wordpress.org/support/users/dagon-design/)
 * (@dagon-design)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/including-wordpress/#post-1035229)
 * Where do you need this code to run? When viewing a page within WP?
 * Or do you simply want an external PHP file (not viewed through WP), but able 
   to access the WP functionality?
 * There are lots of different ways to do this, but it depends on your needs.
 *  Thread Starter [crispina](https://wordpress.org/support/users/crispina/)
 * (@crispina)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/including-wordpress/#post-1035232)
 * Basically, what i’d like to do is call: mywebsite.com/wp-content/themes/MYTHEME/
   mypage.php?abc=def and have it show the header, sidebars, and footer.
 * I’m doing this because I need to pass parameters (?param=whatever) to a page 
   on my site that’s currently being accessed like this: [http://www.mysite.com/category/music](http://www.mysite.com/category/music)
 * Cheers
 *  [dagon-design](https://wordpress.org/support/users/dagon-design/)
 * (@dagon-design)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/including-wordpress/#post-1035235)
 * You mean you just want the page to have the same theme as your WP site? Or you
   want it to actually show data (not just the visual aspect) from your WP install?
 * If you just want a page that _looks_ like your theme, there are better methods
   to use than to access the theme files directly, as they will not mean much without
   the WP code on the back-end to process things.
 * One method would be to create a blank page, view it in your browser, and save
   the page source. You will then have the proper HTML to display the page, without
   the WP code (since it will be only the final code sent to the browser).
 * If you _do_ want all the WP data to be shown, and simply need a way to pass a
   new parameter to a WP page, you can do this.
 * One example can by found in my sitemap generator plugin for WordPress. It basically‘
   tells’ wordpress to look for a new page parameter (in the plugins case – this
   is the page number for the sitemap output).
 * Example code from my script:
 *     ```
       /*
        * Create rewrite rules for sitemap pages
        */
       function ddsg_permalinks($rules) {
       	global $wp_rewrite;
       	$ddsg_sm_name = trim(get_option('ddsg_sm_name'));
       	if ($wp_rewrite->use_verbose_rules || !isset($wp_rewrite->use_verbose_rules)) {
       		$match_form = '$1';
       	} else {
       		$match_form = '$matches[1]';
       	}
   
       	if ($ddsg_sm_name != '') {
       		$newrules[$ddsg_sm_name . '/([0-9]{1,})/?$'] = 'index.php?&pagename=' . $ddsg_sm_name . '&pg=' . $match_form;
       		$newrules = array_merge($newrules,$rules);
       		return $newrules;
       	} else {
       		return $rules;
       	}
       } 
   
       /*
        * Initialize query var for sitemap permalinks
        */
       function ddsg_query_vars ( $vars ) {
       	$vars[] = "pg";
       	return $vars;
       }
   
       add_filter('query_vars', 'ddsg_query_vars');
       add_filter('rewrite_rules_array', 'ddsg_permalinks');
       ```
   
 * Where ‘&pg=’ is the parameter the code sees, but due to the rewrite rules the
   function above passes, it just looks for a numerical value passed after the URL
   of the sitemap page: /sitemap/3/ etc..
 * Then you can use this code to grab the value of the parameter:
 * `$wp_query->query_vars['pg']`
 * Btw, this line in the script simply grabs the page slug for the sitemap page,
   you could just replace this with the slug of whatever page you are getting this
   extra query var from:
 * $ddsg_sm_name = trim(get_option(‘ddsg_sm_name’));
 * Hope that helps 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Including WordPress’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [dagon-design](https://wordpress.org/support/users/dagon-design/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/including-wordpress/#post-1035235)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
