<?php query_posts('showposts=-1&cat=54'); ?> //cat表示获取的分类,-1表示全部获取
<?php if ( have_posts() ): ?>
<?php $i = 0; while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php if( has_post_thumbnail() ) :?>
<?php if($i === 5) : break; endif;?> //5表示获取的条数
<a href="<?php the_permalink() ?>" target="_blank">
<img src="<?php $url = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); echo $url; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"/>
</a>
<?php $i++; endif; ?>
<?php endwhile; ?>
<?php endif;?>
wordpress幻灯图获取代码
最新推荐文章于 2023-02-07 17:14:50 发布