admin管理员组文章数量:1323723
here is the code in single.php and I want to add the loop. anywhere I put endif, I am getting error where can I add it, please?
updated code:
and many thanks in advance.
<div class="row">
<div class="col-md-8">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="blog-post">
<div class="single-post">
<div class="post-thumb">"><img src="<?php the_post_thumbnail_url(); ?>" alt="blog thumb" /></div>
<div class="blog-single-content">
<div class="blog-list-content">
<p class="post-meta">Posted By <a href="#"> <?php the_author(); ?> </a></p>
<h3 class="blog-title"> <?php the_title(); ?> </h3>
<?php the_content(); ?>
</div> <!-- class="blog-list-content" -->
</div> <!-- class="blog-single-content" -->
</div> <!-- class="single-post" -->
</div> <!-- class="blog-post" -->
<?php endif; ?>
<?php endwhile; ?>
<?php comments_template(); ?>
here is the code in single.php and I want to add the loop. anywhere I put endif, I am getting error where can I add it, please?
updated code:
and many thanks in advance.
<div class="row">
<div class="col-md-8">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="blog-post">
<div class="single-post">
<div class="post-thumb">"><img src="<?php the_post_thumbnail_url(); ?>" alt="blog thumb" /></div>
<div class="blog-single-content">
<div class="blog-list-content">
<p class="post-meta">Posted By <a href="#"> <?php the_author(); ?> </a></p>
<h3 class="blog-title"> <?php the_title(); ?> </h3>
<?php the_content(); ?>
</div> <!-- class="blog-list-content" -->
</div> <!-- class="blog-single-content" -->
</div> <!-- class="single-post" -->
</div> <!-- class="blog-post" -->
<?php endif; ?>
<?php endwhile; ?>
<?php comments_template(); ?>
Share
Improve this question
edited Sep 2, 2020 at 18:12
social
asked Sep 2, 2020 at 17:46
socialsocial
713 silver badges9 bronze badges
4
|
1 Answer
Reset to default 0It appears there is a syntax error with this line:
if ( have_posts() ) while ( have_posts() ) : the_post();
You are missing a colon after ( have_posts() )
.
If it's not a theme related issue as mentioned in the comments if you change it to:
"if ( have_posts() ) : while ( have_posts() ) : the_post();
"
Also, the endwhile
should come BEFORE the endif
.
After making these changes it should work.
See Example Here:
<div class="row">
<div class="col-md-8">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="blog-post">
<div class="single-post">
<div class="post-thumb">"><img src="<?php the_post_thumbnail_url(); ?>" alt="blog thumb" /></div>
<div class="blog-single-content">
<div class="blog-list-content">
<p class="post-meta">Posted By <a href="#"> <?php the_author(); ?> </a></p>
<h3 class="blog-title"> <?php the_title(); ?> </h3>
<?php the_content(); ?>
</div> <!-- class="blog-list-content" -->
</div> <!-- class="blog-single-content" -->
</div> <!-- class="single-post" -->
</div> <!-- class="blog-post" -->
<?php endwhile; ?>
<?php endif; ?>
<?php comments_template(); ?>
I always check my PHP with a code checker here: https://phpcodechecker/. I have found it helps a lot when debugging my code. Hopefully, this works for you!
本文标签: how to loop through this in blog single
版权声明:本文标题:how to loop through this in blog single? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742123761a2421844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
the_*()
are a good indication of this. Some themes skip The Loop on single posts since there's one post to display and it's already loaded. – Howdy_McGee ♦ Commented Sep 2, 2020 at 18:02