Php 获取不同页面上的帖子特色图片
我想在页面上显示一些自定义帖子及其特色图片。问题是第一篇文章的图像显示在所有的posts div上 这就是我的代码Php 获取不同页面上的帖子特色图片,php,wordpress,thumbnails,Php,Wordpress,Thumbnails,我想在页面上显示一些自定义帖子及其特色图片。问题是第一篇文章的图像显示在所有的posts div上 这就是我的代码 <?php //solutions $args = array( 'showposts'=>-1, 'category_name' => 'Spage', 'order' => 'ASC', ); $query = new WP_Query( $args ); $asPost = array(); if ( $query-&
<?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
和
代码
$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 }?>
$args=数组(
“展示帖子”=>-1,
'category_name'=>'Spage',
“订单”=>“ASC”,
);
$query=新的WP\u查询($args);
$asPost=array();
如果($query->have_posts()){
而($query->have_posts()){
$query->the_post();
$asPost[]=数组('title'=>$query->post->post\u title,
'content'=>$query->post->post\u内容,'id'=>$query->post->id);
}
}
?>
试试这段代码。我修改了这些'id'=>$query->post->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 }?>
$args=数组(
“展示帖子”=>-1,
'category_name'=>'Spage',
“订单”=>“ASC”,
);
$query=新的WP\u查询($args);
$asPost=array();
如果($query->have_posts()){
而($query->have_posts()){
$query->the_post();
$asPost[]=数组('title'=>$query->post->post\u title,
'content'=>$query->post->post\u内容,'id'=>$query->post->id);
}
}
?>
哦,我离得太近了。非常感谢你!很高兴帮助你哦,我离你很近。非常感谢你!很高兴帮助你