我想使用id或slug显示我的页面内容。我设法在其他一些WP主题中做到这一点,但由于某种原因,这次它不起作用......
我想展示标题,摘录和精选图片
这是我的代码:
<h1 class="text-center light-title"><?php echo the_title() ?></h1>
<span class="light-text"><?php the_excerpt(); ?></span>
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'full', array( 'class' => 'center-block img-responsive')); // show featured image
}
?>
<?php
query_posts("page_id=222");
while ( have_posts() ) : the_post()
?>
<?php //the_content() ?>
<?php
endwhile;
wp_reset_query();
?>
答案 0 :(得分:2)
您没有说出失败的原因,但您的代码顺序似乎并不合适。 the_title()和the_excerpt()通常在里面循环。像这样:
<?php
query_posts("page_id=222");
while ( have_posts() ) : the_post()
?>
<h1 class="text-center light-title"><?php echo the_title() ?></h1>
<span class="light-text"><?php the_excerpt(); ?></span>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'full', array( 'class' => 'center-block img-responsive')); // show featured image
}
?>
<?php //the_content() ?>
<?php
endwhile;
wp_reset_query();
答案 1 :(得分:0)
使用WP_Query
代替query_posts
可以让您更好地控制范围:
<?php
$page = new WP_Query("page_id=374");
while ( $page->have_posts() ) : $page->the_post();
the_content();
endwhile;
?>