【发布时间】:2016-03-04 22:18:16
【问题描述】:
我是 wordpress 的新手,我创建了一个自定义帖子类型“projecten”,现在我想在我创建的页面上显示此类型的所有帖子。
我制作了一个页面模板,一切都很好,并创建了 1 个帖子。 这就是我的页面模板的样子。
<?php
/**
* Template Name: Projecten Template
*/
$projecten = new WP_Query(array('post_type' => 'project'));
wp_reset_postdata();
?>
<?php while (have_posts()) : the_post(); ?>
<div class='full parallax' style='background-image: url(images/@stock/portfolio-header-bg.jpg); color: #fff;'>
<div class='row'>
<div class='twelve columns'>
<div class='big mod modSectionHeader'>
<div class='special-title centered-text'>
<h2 style='color: #fff'>
<?php the_title(); ?>
</h2>
</div>
<h3 class='centered-text' style='color: #fff'><?php the_field('field_56d983a5a4788'); ?></h3>
</div>
</div>
</div>
<div class='four spacing'></div>
</div>
<div class='mod modGallery'>
<?php if ( $projecten->have_posts()): ?>
<?php while ( $projecten->have_posts()): the_post(): ?>
<ul class='gallery large-block-grid-4 medium-block-grid-3 small-block-grid-2'>
<li class='graphic-design'>
<a href='portfolio-item.html'>
<img width="400" height="400" alt="" src="" />
<div class='overlay' >
<div class='thumb-info'>
<h3><?php echo get_the_title(); ?></h3>
<p>hey</p>
</div>
</div>
</a>
</li>
</ul>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
对我来说看起来不错,但不幸的是它不起作用:(
【问题讨论】:
-
你试过删除 wp_reset_postdata();
-
当我这样做时它可以工作,但不使用 wp_reset_postdata(); 不是坏习惯?
-
检查我编辑的答案。
-
您说您的 CPT 是“投影”,但您使用的是
'post_type' => 'project'