WordPress的自定义页面模板 [英] wordpress custom page template

查看:189
本文介绍了WordPress的自定义页面模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为产品"的自定义页面

I have created a custom page named '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 &raquo;</p>'); ?>
        </div>
      </div>
      <?php endwhile; endif; ?>
    </div>
  </div>
</div>
<div id="clear"> </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body></html>

但是它没有显示我的帖子,我在做什么错了?

but it doesnt show my posts, what am I doing wrong ?

推荐答案

此代码确实将您的帖子显示为博客页面,此代码仅显示页面产品"的内容,要显示所有帖子,您必须使用另一个代码:

This Code doenst shows your Posts like an Blog Page, this Code shows only the Content of the Page "Products", to show all your Posts, you must use another code:

<?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 &raquo;</p>'); ?>
        </div>
      </div>
      <?php endwhile; endif; ?>
    </div>
  </div>
</div>
<div id="clear"> </div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</body></html>

这篇关于WordPress的自定义页面模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆