在不同页面上获取 post 个精选图片
Getting post featured image on different page
我想在页面上显示一些自定义 post 及其特色图片。问题是第一个 post 的图像显示在所有 post 的 div 上。
这是我的代码
<?php
//solutions
$args = array(
'showposts'=>-1,
'category_name' => 'Spage',
'order' => 'ASC',
);
$query = new WP_Query( $args );
$asPost = array();
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$asPost[] = array('title' => $query->post->post_title,
'content' => $query->post->post_content);
}
}
?>
<?php $count = 0; ?>
<?php if(!empty($asPost)){ ?>
<?php foreach($asPost as $item){ ?>
<div class="container box<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>">
<div class="item">
<p class="headline font--h5 accent--teal"><?php echo $item['title']; ?></p>
<div class="fullwidth">
<?php the_post_thumbnail(); ?>
</div>
<div class="font--h5 body body--dark">
<?php echo apply_filters('the_content',$item['content']);?>
</div>
</div>
</div>
<?php }?>
<?php }?>
如何拍出正确的照片?
试试这个代码。我修改了这些 'id'=>$query->post->ID
和 <?php get_the_post_thumbnail($item['id']); ?>
代码。
$args = array(
'showposts'=>-1,
'category_name' => 'Spage',
'order' => 'ASC',
);
$query = new WP_Query( $args );
$asPost = array();
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$asPost[] = array('title' => $query->post->post_title,
'content' => $query->post->post_content, 'id'=>$query->post->ID);
}
}
?>
<?php $count = 0; ?>
<?php if(!empty($asPost)){ ?>
<?php foreach($asPost as $item){ ?>
<div class="container box<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>">
<div class="item">
<p class="headline font--h5 accent--teal"><?php echo $item['title']; ?></p>
<div class="fullwidth">
<?php get_the_post_thumbnail($item['id']); ?>
</div>
<div class="font--h5 body body--dark">
<?php echo apply_filters('the_content',$item['content']);?>
</div>
</div>
</div>
<?php }?>
<?php }?>
我想在页面上显示一些自定义 post 及其特色图片。问题是第一个 post 的图像显示在所有 post 的 div 上。
这是我的代码
<?php
//solutions
$args = array(
'showposts'=>-1,
'category_name' => 'Spage',
'order' => 'ASC',
);
$query = new WP_Query( $args );
$asPost = array();
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$asPost[] = array('title' => $query->post->post_title,
'content' => $query->post->post_content);
}
}
?>
<?php $count = 0; ?>
<?php if(!empty($asPost)){ ?>
<?php foreach($asPost as $item){ ?>
<div class="container box<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>">
<div class="item">
<p class="headline font--h5 accent--teal"><?php echo $item['title']; ?></p>
<div class="fullwidth">
<?php the_post_thumbnail(); ?>
</div>
<div class="font--h5 body body--dark">
<?php echo apply_filters('the_content',$item['content']);?>
</div>
</div>
</div>
<?php }?>
<?php }?>
如何拍出正确的照片?
试试这个代码。我修改了这些 'id'=>$query->post->ID
和 <?php get_the_post_thumbnail($item['id']); ?>
代码。
$args = array(
'showposts'=>-1,
'category_name' => 'Spage',
'order' => 'ASC',
);
$query = new WP_Query( $args );
$asPost = array();
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$asPost[] = array('title' => $query->post->post_title,
'content' => $query->post->post_content, 'id'=>$query->post->ID);
}
}
?>
<?php $count = 0; ?>
<?php if(!empty($asPost)){ ?>
<?php foreach($asPost as $item){ ?>
<div class="container box<?php if( $count%3 == 0 ) { echo '-1'; }; $count++; ?>">
<div class="item">
<p class="headline font--h5 accent--teal"><?php echo $item['title']; ?></p>
<div class="fullwidth">
<?php get_the_post_thumbnail($item['id']); ?>
</div>
<div class="font--h5 body body--dark">
<?php echo apply_filters('the_content',$item['content']);?>
</div>
</div>
</div>
<?php }?>
<?php }?>