【问题标题】:Edit wordpress loop to display thumbnail and excerpt编辑 wordpress 循环以显示缩略图和摘录
【发布时间】:2016-12-05 17:24:54
【问题描述】:

我尝试实现一个 wordpress 循环来在我的博客上显示文章。我正在尝试创建这样的设计:www.freileben.net

我的 wordpress 循环如下所示:

.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>

我不知道如何解决这个问题,因为我使用的所有图像都有不同的尺寸,而且它们的位置也不相同。

【问题讨论】:

    标签: php html css wordpress themes


    【解决方案1】:

    试试下面的代码:

       <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 帖子类型或默认的 WordPress 帖子吗?
    • 我有一个默认帖子
    • 哇,谢谢,看起来不错!但是我仍然遇到不同帖子之间的距离错误的问题,我无法通过在它周围放置一个 div 并将它们彼此相邻放置来解决它。你知道解决办法吗?
    猜你喜欢
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 1970-01-01
    相关资源
    最近更新 更多