| WordPress Meet HTML |
| by REFERDEAL |
| Article Source: Original |
Next, we have to tell WordPress about this new template. To achieve
this we need to customize core PHP files. The idea is to piggy back
on the logic that process single page, and display our new template
if our marker exist.
- assign a new query parameter as a marker for new template
- parameter can be passed via session or query string
- in template-loader, branch to new template if we detect the
presence of the specific marker
We designate z as the template marker. z can
be passed into WP either via URL (http://.../?z=id) or in
session ($SESSION['z'] = id). When we detect the presence
of z (if isset('z')), this is the que to display the new
template.
First, tell class WP that 'z' is a valid public query variable
in class.php.
class WP {
/*-- wk --*/
// include z as part of public query vars
var $public_query_vars = array('z',
'm', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact',
'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb',
'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour',
'minute', 'second', 'name', 'category_name', 'feed', 'author_name',
'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment',
'attachment_id', 'subpost', 'subpost_id');
/*-- == --*/
"single page" logic is activated when parameter 'p'
is set. Here we intercept to initialize 'p' when
we detect our template marker 'z' is set in class.php
at the end of parse_request().
/*-- wk --*/
// parameter can also be set via session. we initialize query_vars
here
// query_string _GET will take precedent over session data
if (isset($_SESSION[ 'z']) || !empty($_GET[ 'z'])) {
if(empty($_GET[ 'z']))
$this->query_vars[ 'z'] = $_SESSION[ 'z'];
$this->query_vars['p'] = $_SESSION[ 'z'];
}
/*-- == --*/
if ( isset($error) )
$this->query_vars['error'] = $error;
}
Lastly, when WP is about
to display single_template in template-loader.php, we put in additional if-else statement where
if our 'z' marker is set, we display z template, otherwise use
the default single template.
} else if ( is_single() && get_single_template()
) {
if ( is_attachment() )
add_filter('the_content', 'prepend_attachment');
include(get_single_template());
exit;
/*-- wk --*/
// we piggy back on single_template logic and branch
// to new template if z is set in the query_vars
global $wp_query;
$wpvar = 'z';
if(isset($wp_query->query_vars['z'])) {
include(get_query_template('z'));
} else {
include(get_single_template());
exit;
}
/*-- == --*/
} else if ( is_page() && get_page_template() ) {
We are now ready to modify the static article HTML.
Step 3..
|