如果您不关心此页面的URL,可以在不使用Ajax的情况下使用$_GET
参数。看一看:
// If we have $_GET parameter in URL, we save it in $page variable. Otherwise $page will be empty.
( isset( $_GET[\'page\'] ) ) ? $page = ( int ) $_GET[\'page\'] : $page = \'\';
get_header();
if ( $page != \'\' ) :
// If $page variable is not empty, we get post(page) by ID
$header_page = get_post( $page );
// Then we can print anything we want, using this post object: title, content, custom fields, thumbnail, etc.
echo $header_page->post_title; // Post title
echo apply_filters( \'the_content\', $header_page->post_content ); // Post content
echo get_post_meta( $page, \'custom_meta_key\', 1 ); // Any custom field
echo get_the_post_thumbnail ( $page, \'post-thumbnail\' ); // Post thumbnail
endif;
// Our links will look like so:
?><a href="<?php echo $_SERVER[\'REQUEST_URI\']; ?>?page=123">Some title</a><?php
// Here 123 is ID of page, which content we want to show.
get_footer();
单击此类链接时,您将转到同一页面,但URL中有一个新参数。例如:
http://site.ru/page -> http://site.ru/page?page=123.
但是如果您想拥有“干净”的URL,那么就需要Ajax。