duanqiang7631 2016-05-12 09:28
浏览 20
已采纳

编辑wordpress循环以显示缩略图和摘录

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

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.

</div>
  • 写回答

1条回答 默认 最新

  • dqknycyt92288 2016-05-12 09:44
    关注

    Try this below code :

       <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(); ?>
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部