wordpress输出额外的html代码

时间:2018-07-01 10:51:22

标签: wordpress wordpress-theming

我正在WordPress中构建主题,我是新手,并且正在输出图像HTML,请帮助我解决此问题,谢谢。

<?php

            $args = array( 'numberposts' => 4, 'order'=> 'ASC', 'orderby' => 'title', 'category' => '5' );
            $postslist = get_posts( $args );
            foreach ($postslist as $post) :  setup_postdata($post); ?> 

              <li>
              <div class="timeline-image">
                <a href="<?php the_permalink(); ?>">
                  <img class="rounded-circle img-fluid" src="<?php echo the_post_thumbnail(); ?>">
                </a>
              </div>
              <div class="timeline-panel">
                <div class="timeline-heading">
                  <h4 class="subheading text-left"><?php the_title(); ?></h4>
                </div>
                <div class="timeline-body">
                  <p class="text-muted text-justify"><?php the_excerpt(); ?> &nbsp;
                    <a href="readmore.html">Read More >></a>
                  </p>
                </div>
              </div>
            </li>

<?php endforeach; ?>

1 个答案:

答案 0 :(得分:0)

您应该这样循环浏览帖子,而不要使用foreach

<?php
$args = array(
   'post_type' => 'post',
   'posts_per_page' => 4,
   'orderby' => 'title',
   'order' => 'ASC',
   'category__in' => 5
);
$loop = new wp_query( $args );
while( $loop->have_rows() ) : $loop->the_row();
?>
   Your article content…
   <h4 class="subheading text-left"><?php the_title(); ?></h4>
<?php endif; ?>

如果您需要遍历其他自定义帖子类型,请使用this guide