这就是我工作的方式:
将此添加到函数中。php:
function include_template_function( $template_path ) {
global $wp;
if ($wp->request == \'state\') {
$template_path = locate_template( array ( \'state.php\' ) );
}
return $template_path;
}
$state_name = $_GET[\'st\']; //this is added to use as a global variable
将此添加到标题。php,因为WP认为它提供的是404页
if ($wp->request == \'state\') {
echo \'Member Centers in \' . $state_name . \' | \';
} else {
wp_title( \'|\', true, \'right\' );
}
?>
</title>
将此添加到基本模板(page.php):
<?php
$baseURL = esc_url( home_url( \'/\' ) );
$ak_link = $baseURL . \'state?st=Alaska\'; // for each state
?>
<a href="<?php echo $ak_link; ?>">Show Alaska Pages</a>
已创建状态。处理状态查询的php模板:
<?php global $state_name; ?> ?>
<?php
$mypages = get_pages(\'child_of=\'.$parent_page_id.\'&sort_order=ASC&parent=\'.$parent_page_id.\'&meta_key=ctr_state&meta_value=\'.$state_name);
foreach($mypages as $page)
{
?>
... Do Stuff! ...
<?php } ?>