duanqiang7631 2016-05-12 17: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 17: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(); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址