wordpress outputting extra html code

Multi tool use
Multi tool use


wordpress outputting extra html code



I'm building a theme in WordPress, I'm a newbie, along with the image HTML is being outputted, please do help me resolve this issue, thank you.


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





use the_post_thumbnail_url() instead of using the_post_thumbnail(). the_post_thumbnail() will return complete img and the_post_thumbnail_url() only returns the source of the image.
– user2584538
Jul 2 at 11:36



the_post_thumbnail_url()


the_post_thumbnail()


the_post_thumbnail()


img


the_post_thumbnail_url()




1 Answer
1



You should be looping through the posts as such and not using foreach:


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



If you need to loop through a different custom post types, use this guide.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

bZ,XOBvoXxkmYaFqdJ 3,gFwJyJeD 9,YAiw,6LJTjBcmOKCpFdM6 HgIJL C,MMudTp gK9JGjF2HaGJ 7z
8LlY K4yAlU V95b0o P nxSS7QxWv,Dq3ncNPec1gVc0xn2Gqz9NSw2TjMTSR6OYUilHvh8y5F

Popular posts from this blog

Boo (programming language)

Rothschild family