我创建了一个名为'products'的自定义页面
<?php
/*
Template Name: Products
*/
?>
<?php get_header(); ?>
<div id="products_content">
<div id="products_page_header">
<div id="products_page" title="محصولات">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title();?>
</h2>
<div class="entrytext">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
</div>
</div>
<?php endwhile; endif; ?>
</div>
</div>
</div>
<div id="clear"> </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body></html>
但它没有显示我的帖子,我做错了什么?
答案 0 :(得分:2)
此代码不会显示您的帖子,如博客页面,此代码仅显示网页内容“产品”,要显示您的所有帖子,您必须使用其他代码:
<?php
/*
Template Name: Products
*/
?>
<?php get_header(); ?>
<div id="products_content">
<div id="products_page_header">
<div id="products_page" title="محصولات">
<?php $query = new WP_Query('showposts=10'.'&paged='.$paged); ?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title();?>
</h2>
<div class="entrytext">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
</div>
</div>
<?php endwhile; endif; ?>
</div>
</div>
</div>
<div id="clear"> </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body></html>
答案 1 :(得分:0)
对于标准的wordpress循环,此<?php endwhile; endif; ?>
应为
<?php endwhile; ?>
<?php else : ?>
(optional: Sorry, but you are looking for something that isn't here.)
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer();?>