wordpress自定义页面模板显示帖子两次
问题描述:
我不是一个wordpress专家,所以想知道如果有人可以帮助我。我为一个页面创建了一个自定义页面模板,这样我就可以在该页面上聚合并显示来自一个类别的帖子。不过,我迄今在该类别中创建了一篇文章,但它在页面上显示两次。从类别中获取的帖子显示在“div id = main”div中。这里是页面模板代码:wordpress自定义页面模板显示帖子两次
<?php /* Template Name: Deals Page */ ?>
<?php get_header(); ?>
</div>
//<?php while (have_posts()) : the_post(); ?>
<div id="title-bar">
<h1 class="bar-entry-title container"><?php the_title(); ?></h1>
</div>
<?php endwhile; ?>
<div class="container col-md-12"><!-- restart previous section-->
<div id="primary" class="content-area col-md-8">
<main id="main" class="site-main" role="main">
<?php query_posts('category_name=deals &posts_per_page=20'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title('<h2>', '</h2>'); ?>
<?php the_content(); ?>
//<?php get_template_part('content', 'page'); ?>
<?php endwhile; // end of the loop. ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if (comments_open() || '0' != get_comments_number())
comments_template();
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_sidebar('footer'); ?>
<?php get_footer(); ?>
你知道它为什么显示两次?我看不出为什么。
答
您正在运行两个循环。您的评论栏位于第五行的PHP之外。
更改此//<?php while (have_posts()) : the_post(); ?>
这个<?php // while (have_posts()) : the_post(); ?>
而且注释掉第一<?php endwhile; ?>
各地的9号线,否则你会得到一个PHP错误
+0
非常感谢你! – Michele 2014-11-07 05:58:48
噢 - 页面是在这里:[链接]( http://abyssinianguineapigtips.com/deals/) – Michele 2014-11-06 23:21:13
由于它不在php代码中,所以此评论无效:'// 应该是' – Rasclatt 2014-11-06 23:22:54
非常感谢你! – Michele 2014-11-07 05:58:37