我是wordpress的新手,我做了一个自定义的帖子类型'projecten‘,现在我想在我创建的页面上显示来自这个类型的所有帖子。
我做了一个页面模板,一切都很好,并创建了一个帖子。这是我的页面模板的样子。
<?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; ?>它在我看来还可以,但不幸的是它不起作用:
发布于 2016-03-04 21:47:33
这是对你的代码的编辑,我认为这会对你有帮助。您在查询中遗漏了"projecten“的"en”。
我还围绕li标记而不是ul标记包装了循环,并做了一些其他调整。
<?php
/**
* Template Name: Projecten Template
*/
$projecten = new WP_Query(array('post_type' => 'projecten'));
?>
<div class='full parallax' style='background-image: url(<?php bloginfo('template_url');?>/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() ) { ?>
<ul class='gallery large-block-grid-4 medium-block-grid-3 small-block-grid-2'>
<?php while ( $projecten->have_posts() ) { ?>
<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 the_title(); ?></h3>
<p>hey</p>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>发布于 2016-03-04 21:49:56
删除wp_reset_postdata();它将在循环结束后出现。你已经忘了这件事
$projecten = new WP_Query(array('post_type' => 'project'));
while ($projecten->have_posts()) : $projecten->the_post(); 发布于 2016-03-04 22:18:16
<?php
/**
* Template Name: Projecten Template
*/
$projecten = new WP_Query(array('post_type' => 'project'));
?>
<?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();
?>并通过传递post_id获取如下所示的特色图片
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>将您的单个页面创建为single-.php,您将获得该页面中与该特定页面相关的所有内容。
作为参考,您可以查看二十五主题中的single.php
https://stackoverflow.com/questions/35797138
复制相似问题