编辑wordpress循环以显示缩略图和摘录 [英] Edit wordpress loop to display thumbnail and excerpt
本文介绍了编辑wordpress循环以显示缩略图和摘录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试实现一个wordpress循环显示我的博客上的文章。我试图创建一个这样的设计:www.freileben.net
I try to realize a wordpress loop to display the articles on my blog. I'm trying to create a design like this: www.freileben.net
我的wordpress循环看起来像这样:
My wordpress loop looks like this:
.thumbnail {
float: left;
margin-right: 50px;
}
#post {
margin-top: 120px;
padding-top: 15px;
}
<article id="post">
<div id="thumbnail">
<?php if ( function_exists( 'has_post_thumbnail') && has_post_thumbnail() ) { the_post_thumbnail(array(350,220), array( "class"=>"thumbnail")); } ?>
</div>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
</article>
我不知道如何解决这个问题,因为我使用的所有图像有不同的大小,他们不在同一个位置。
I don't know how to solve the problem because all of the images I use have got a different size and they are not in the same position.
推荐答案
请尝试以下代码:
<article id="post">
<?php
// the query
$args = array('');
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) { ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<div id="thumbnail">
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail(array( "class"=>"thumbnail"));
}
?>
</div>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<?php } } else { ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php } ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
这篇关于编辑wordpress循环以显示缩略图和摘录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文