訪問地址:xx/?page_id=12
如果是在當前頁面,只需要通過循環就可以輸出對應的信息
<?php if(have_posts()):while(have_posts()):the_post(); ?> <div class="post"> <h1 class="title"><? the_title();?></h1> <? the_content();?> </div> <? endwhile; endif; ?>
但是如果在其他頁面呢?
知道ID可以這樣獲取內容:
$page_id = 12; $page_data = get_page( $page_id ); echo '<h3>'. $page_data->post_title .'</h3>';// 標題 echo apply_filters('the_content', $page_data->post_content); //內容
如果知道別名:
<?php $name = 'about-us'; //page別名 global $wpdb; $page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'"); echo $page_data = get_page( $page_id )->post_content; ?>
