Php Wordpress页面模板未呈现

Php Wordpress页面模板未呈现,php,wordpress,Php,Wordpress,我们的博客页面应该是这样的: 然而,它最终看起来像这样-完全是空的 尽管页面主题设置正确,且模板文件包含以下代码,但仍然存在这种情况: <?php /** * Template Name: Blog */ get_header(); ?> <div class="box clearfix color2"> <div id="content" class="three_fourth"> <?php $temp = $wp_q

我们的博客页面应该是这样的:

然而,它最终看起来像这样-完全是空的

尽管页面主题设置正确,且模板文件包含以下代码,但仍然存在这种情况:

    <?php
/**
 * Template Name: Blog
 */

get_header(); ?>
<div class="box clearfix color2">
    <div id="content" class="three_fourth">

  <?php
  $temp = $wp_query;
  $wp_query= null;
  $wp_query = new WP_Query();
  $wp_query->query('showposts=5'.'&paged='.$paged);
  ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
      <header>
        <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <div class="post-meta">
          <div class="fleft">Posted in: <?php the_category(', ') ?> | <time datetime="<?php the_time('Y-m-d\TH:i'); ?>"><?php the_time('F j, Y'); ?> at <?php the_time() ?></time> , by <?php the_author_posts_link() ?></div>
          <div class="fright"><?php comments_popup_link('No comments', 'One comment', '% comments', 'comments-link', 'Comments are closed'); ?></div>
        </div><!--.post-meta-->
      </header>
      <?php echo '<div class="featured-thumbnail">'; the_post_thumbnail(); echo '</div>'; ?>
      <div class="post-content">
        <div class="excerpt"><?php $excerpt = get_the_excerpt(); echo my_string_limit_words($excerpt,50);?><a href="<?php the_permalink() ?>" class="link-more">Read more</a></div>
      </div>
    </article>

  <?php endwhile; ?>

  <?php if ( $wp_query->max_num_pages > 1 ) : ?>
    <nav class="oldernewer">
      <div class="older">
        <?php next_posts_link('&laquo; Older Entries') ?>
      </div><!--.older-->
      <div class="newer">
        <?php previous_posts_link('Newer Entries &raquo;') ?>
      </div><!--.newer-->
    </nav><!--.oldernewer-->
  <?php endif; ?>

  <?php $wp_query = null; $wp_query = $temp;?>

</div><!--#content-->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>


发帖于:|事实上,我已经在WordPress中遇到了这种情况。 这不是你代码的错。可能是WordPress的Bug

尝试更改您的页面名称一次。 像



然后再次登录,检查是否显示新的自定义页面选项。

博客中是否有任何内容?i、 你添加了网页和帖子了吗?有一篇帖子被添加到了博客中。可以在这里看到-我使用设置>阅读选项将博客页面设置为显示帖子的位置。除此之外,我还没有告诉wordpress将帖子放到博客页面上。“我可能错过了一些非常明显的东西……”布莱斯·萨默尔。转到页面并编辑博客页面,在下拉列表中将“页面模板”设置为“博客”,然后保存。有趣的是,您的评论启发我测试在“设置”>“阅读选项”中将页面作为帖子页面删除是否可以解决问题。是的。谢谢你,詹姆斯!加上这个作为答案,我可以给你的信用。“哈哈!”布莱斯·萨默尔说。在设置>阅读选项中设置博客页面会导致Wordpress使用index.php文件而不是这个“blog.php”文件。注意:wordpress设置是推荐的方法,模板做得不对。。
  <?php
/**
 * Template Name: Blog_new
 */
?>