自定义帖子类型无法正确显示

时间:2012-10-11 13:58:12

标签: wordpress custom-post-type

我正在尝试使用boostrap响应框架在我正在开发的主题中显示我的自定义帖子类型。除了我无法正确显示自定义帖子类型之外,一切都很好用。我循环遍历帖子类型,无法结束我的<div>,导致页脚被推到左侧。看看:

<?php 
$query = new WP_Query(array('post_type'=>'services','posts_per_page'=>'5'));
while ($query->have_posts()) : $query->the_post();?>

<!-- Post Start -->
<div class="row">
<div class="span2">
<?php the_post_thumbnail(array(150,150), array('class'=>'service-image')); ?>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?></h2></a>
<p><?php the_content(); ?></p>
<p><a class="btn" href="<?php the_permalink(); ?>">View details &raquo;</a></p>
</div>

<?php endwhile; wp_reset_query(); ?></div></div></div></div></div>
<!-- Post End -->

我必须在查询结尾处堆叠</div>,以便自定义帖子正确显示,并且页脚返回到正确的位置。我希望有人可以看到我的错误,因为我迷路了。任何帮助或指导都会很棒。这个主题可以在crothersenvironmental.com的发展中看到。在现场网站上,我删除了所有结尾div以进行故障排除。

提前致谢。

2 个答案:

答案 0 :(得分:0)

你的第一行是否应该在循环之外声明?目前它正在为每个帖子循环一次,但它在循环期间没有被关闭。

<div class="row">
<?php 
$query = new WP_Query(array('post_type'=>'services','posts_per_page'=>'5'));
while ($query->have_posts()) : $query->the_post();?>

<!-- Post Start -->
<div class="span2">
<?php the_post_thumbnail(array(150,150), array('class'=>'service-image')); ?>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?></h2></a>
<p><?php the_content(); ?></p>
<p><a class="btn" href="<?php the_permalink(); ?>">View details &raquo;</a></p>
</div><!--span2-->

<?php endwhile; wp_reset_query(); ?></div><!--row--></div></div></div></div>
<!-- Post End -->

答案 1 :(得分:0)

  • 正如 gArn 所说,你的 div应该在循环之前
  • 您不应将<p>标记与the_content()
  • 一起使用
  • 您的</a>结束标记应该在</h2>
  • 之前

您可以尝试:

<div class="row">
    <?php 
    $query = new WP_Query(array('post_type'=>'services','posts_per_page'=>'5'));
    while ($query->have_posts()) : $query->the_post(); ?>

    <!-- Post Start -->
    <div class="span2">
        <?php the_post_thumbnail(array(150,150), array('class'=>'service-image')); ?>
        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <?php the_title(); ?></a></h2>
        <div><?php the_content(); ?></div>
        <p><a class="btn" href="<?php the_permalink(); ?>">View details &raquo;</a></p>
    </div>
    <!-- Post End -->

    <?php endwhile; wp_reset_query(); ?>
</div>
相关问题